#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    # ワーシャルフロイド
    def warshall_floyd(d, N):
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    d[i][j]=min(d[i][j], d[i][k] + d[k][j])
    
    N,M,L=MI()
    ABC=LLIN(M)
    d=[[float("inf")] * N for i in range(N)]
    for i in range(N):
        d[i][i] = 0
    
    for a,b,c in ABC:
        a-=1
        b-=1
        d[a][b]=c
        d[b][a]=c

    warshall_floyd(d,N)

    D=[[float("inf")] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                D[i][j] = 1
        
    warshall_floyd(D,N)

    Q=I()
    ST=LLIN_(Q)
    for s,t in ST:
        if D[s][t]==inf:
            print(-1)
        else:
            print(D[s][t]-1)
    

if __name__ == '__main__':
    main() import sys sys sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from math import floor,ceil,sqrt,factorial,log from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict,deque from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from bisect import bisect_left,bisect_right from copy import deepcopy inf=float('inf') inf float('inf') float 'inf' mod = 10**9+7 mod 10**9+7 10**9 10 9 7 def pprint(*A): 
    for a in A:     print(*a,sep='\n') pprint for a in A:     print(*a,sep=' a A *A def INT_(n): return int(n)-1 INT_ n n def MI(): return map(int,input().split()) MI def MF(): return map(float, input().split()) MF def MI_(): return map(INT_,input().split()) MI_ def LI(): return list(MI()) LI int(x) - 1 for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) - 1 int(x) int x 1 def LI_(): return [int(x) - 1 for x in input().split()] LI_ def LF(): return list(MF()) LF I() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) I() I def LIN(n:int): return [I() for _ in range(n)] LIN n:int n LI() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI() LI def LLIN(n: int): return [LI() for _ in range(n)] LLIN n: int n LI_() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI_() LI_ def LLIN_(n: int): return [LI_() for _ in range(n)] LLIN_ n: int n list(map(int, l.split() )) for l in input() for l in input() l input() input for l in input() list(map(int, l.split() )) list map(int, l.split() ) map int l.split() l.split l split def LLI(): return [list(map(int, l.split() )) for l in input()] LLI def I(): return int(input()) I def F(): return float(input()) F def ST(): return input().replace('\n', '') ST def main():
    # ワーシャルフロイド
    def warshall_floyd(d, N):
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    d[i][j]=min(d[i][j], d[i][k] + d[k][j])
    
    N,M,L=MI()
    ABC=LLIN(M)
    d=[[float("inf")] * N for i in range(N)]
    for i in range(N):
        d[i][i] = 0
    
    for a,b,c in ABC:
        a-=1
        b-=1
        d[a][b]=c
        d[b][a]=c

    warshall_floyd(d,N)

    D=[[float("inf")] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                D[i][j] = 1
        
    warshall_floyd(D,N)

    Q=I()
    ST=LLIN_(Q)
    for s,t in ST:
        if D[s][t]==inf:
            print(-1)
        else:
            print(D[s][t]-1)
     main def warshall_floyd(d, N):
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    d[i][j]=min(d[i][j], d[i][k] + d[k][j])
    
     warshall_floyd for k in range(N):
            for i in range(N):
                for j in range(N):
                    d[i][j]=min(d[i][j], d[i][k] + d[k][j])
    
     k range(N) range N for i in range(N):
                for j in range(N):
                    d[i][j]=min(d[i][j], d[i][k] + d[k][j])
    
     i range(N) range N for j in range(N):
                    d[i][j]=min(d[i][j], d[i][k] + d[k][j])
    
     j range(N) range N d[i][j]=min(d[i][j], d[i][k] + d[k][j]) d[i][j] [i] d i j min(d[i][j], d[i][k] + d[k][j]) min d[i][j] [i] d i j d[i][k] + d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j d d N N N,M,L=MI() N MI() MI M L ABC=LLIN(M) ABC LLIN(M) LLIN M [float("inf")] * N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [float("inf")] * N [float("inf")] float("inf") float "inf" N d=[[float("inf")] * N for i in range(N)] d [[float("inf")] * N for i in range(N)] for i in range(N):
        d[i][i] = 0
    
     i range(N) range N d[i][i] = 0 d[i][i] [i] d i i 0 for a,b,c in ABC:
        a-=1
        b-=1
        d[a][b]=c
        d[b][a]=c

     a b c ABC a-=1 a 1 b-=1 b 1 d[a][b]=c d[a][b] [a] d a b c d[b][a]=c d[b][a] [b] d b a c warshall_floyd(d,N) warshall_floyd d N [float("inf")] * N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [float("inf")] * N [float("inf")] float("inf") float "inf" N D=[[float("inf")] * N for i in range(N)] D [[float("inf")] * N for i in range(N)] for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                D[i][j] = 1
        
     i range(N) range N for j in range(N):
            if d[i][j]<=L:
                D[i][j] = 1
        
     j range(N) range N if d[i][j]<=L:
                D[i][j] = 1
        
     d[i][j]<=L d[i][j] [i] d i j L D[i][j] = 1 D[i][j] [i] D i j 1 warshall_floyd(D,N) warshall_floyd D N Q=I() Q I() I ST=LLIN_(Q) ST LLIN_(Q) LLIN_ Q for s,t in ST:
        if D[s][t]==inf:
            print(-1)
        else:
            print(D[s][t]-1)
     s t ST if D[s][t]==inf:
            print(-1)
        else:
            print(D[s][t]-1)
     D[s][t]==inf D[s][t] [s] D s t inf print(-1) print -1 print(D[s][t]-1) print D[s][t]-1 D[s][t] [s] D s t 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def LLIN(n: int): return [LI() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] LLIN def MF(): return map(float, input().split()) def MF(): return map(float, input().split()) MF def MI(): return map(int,input().split()) def MI(): return map(int,input().split()) MI def F(): return float(input()) def F(): return float(input()) F def LLIN_(n: int): return [LI_() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] LLIN_ def LI(): return list(MI()) def LI(): return list(MI()) LI def LF(): return list(MF()) def LF(): return list(MF()) LF mod = 10**9+7 10**9+7 mod inf=float('inf') float('inf') inf def MI_(): return map(INT_,input().split()) def MI_(): return map(INT_,input().split()) MI_ def LIN(n:int): return [I() for _ in range(n)] def LIN(n:int): return [I() for _ in range(n)] LIN def LLI(): return [list(map(int, l.split() )) for l in input()] def LLI(): return [list(map(int, l.split() )) for l in input()] LLI def main():
    # ワーシャルフロイド
    def warshall_floyd(d, N):
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    d[i][j]=min(d[i][j], d[i][k] + d[k][j])
    
    N,M,L=MI()
    ABC=LLIN(M)
    d=[[float("inf")] * N for i in range(N)]
    for i in range(N):
        d[i][i] = 0
    
    for a,b,c in ABC:
        a-=1
        b-=1
        d[a][b]=c
        d[b][a]=c

    warshall_floyd(d,N)

    D=[[float("inf")] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                D[i][j] = 1
        
    warshall_floyd(D,N)

    Q=I()
    ST=LLIN_(Q)
    for s,t in ST:
        if D[s][t]==inf:
            print(-1)
        else:
            print(D[s][t]-1)
     def main():
    # ワーシャルフロイド
    def warshall_floyd(d, N):
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    d[i][j]=min(d[i][j], d[i][k] + d[k][j])
    
    N,M,L=MI()
    ABC=LLIN(M)
    d=[[float("inf")] * N for i in range(N)]
    for i in range(N):
        d[i][i] = 0
    
    for a,b,c in ABC:
        a-=1
        b-=1
        d[a][b]=c
        d[b][a]=c

    warshall_floyd(d,N)

    D=[[float("inf")] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                D[i][j] = 1
        
    warshall_floyd(D,N)

    Q=I()
    ST=LLIN_(Q)
    for s,t in ST:
        if D[s][t]==inf:
            print(-1)
        else:
            print(D[s][t]-1)
     main input=sys.stdin.readline sys.stdin.readline input def pprint(*A): 
    for a in A:     print(*a,sep='\n') def pprint(*A): 
    for a in A:     print(*a,sep='\n') pprint def INT_(n): return int(n)-1 def INT_(n): return int(n)-1 INT_ def ST(): return input().replace('\n', '') def ST(): return input().replace('\n', '') ST def LI_(): return [int(x) - 1 for x in input().split()] def LI_(): return [int(x) - 1 for x in input().split()] LI_ def I(): return int(input()) def I(): return int(input()) I
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    # ワーシャルフロイド
    def warshall_floyd(d, N):
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    d[i][j]=min(d[i][j], d[i][k] + d[k][j])
    
    N,M,L=MI()
    ABC=LLIN(M)
    d=[[float("inf")] * N for i in range(N)]
    for i in range(N):
        d[i][i] = 0
    
    for a,b,c in ABC:
        a-=1
        b-=1
        d[a][b]=c
        d[b][a]=c

    warshall_floyd(d,N)

    D=[[float("inf")] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j]<=L:
                D[i][j] = 1
        
    warshall_floyd(D,N)

    Q=I()
    ST=LLIN_(Q)
    for s,t in ST:
        if D[s][t]==inf:
            print(-1)
        else:
            print(D[s][t]-1)
    

if __name__ == '__main__':
    main()