def floyd_warshall(G):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j]=min(G[i][j],G[i][k]+G[k][j])

import sys
input=sys.stdin.readline
INF=10**30
N,M,L=map(int,input().split())
dp1=[[INF]*N for i in range(N)]
for i in range(N):
    dp1[i][i]=0
for _ in range(M):
    A,B,C=map(int,input().split())
    A,B=A-1,B-1
    dp1[A][B]=C
    dp1[B][A]=C

floyd_warshall(dp1)

dp2=[[INF]*N for i in range(N)]
for i in range(N):
    for j in range(N):
        if i==j:
            dp2[i][j]=0
        else:
            dp2[i][j]=1 if dp1[i][j]<=L else INF
floyd_warshall(dp2)

Q=int(input())
for _ in range(Q):
    s,t=map(lambda x:int(x)-1,input().split())
    print (dp2[s][t]-1 if dp2[s][t]!=INF else -1) def floyd_warshall(G):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j]=min(G[i][j],G[i][k]+G[k][j]) floyd_warshall for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j]=min(G[i][j],G[i][k]+G[k][j]) k range(N) range N for i in range(N):
            for j in range(N):
                G[i][j]=min(G[i][j],G[i][k]+G[k][j]) i range(N) range N for j in range(N):
                G[i][j]=min(G[i][j],G[i][k]+G[k][j]) j range(N) range N G[i][j]=min(G[i][j],G[i][k]+G[k][j]) G[i][j] [i] G i j min(G[i][j],G[i][k]+G[k][j]) min G[i][j] [i] G i j G[i][k]+G[k][j] G[i][k] [i] G i k G[k][j] [k] G k j G G import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline INF=10**30 INF 10**30 10 30 N,M,L=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L [INF]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF]*N [INF] INF N dp1=[[INF]*N for i in range(N)] dp1 [[INF]*N for i in range(N)] for i in range(N):
    dp1[i][i]=0 i range(N) range N dp1[i][i]=0 dp1[i][i] [i] dp1 i i 0 for _ in range(M):
    A,B,C=map(int,input().split())
    A,B=A-1,B-1
    dp1[A][B]=C
    dp1[B][A]=C _ range(M) range M A,B,C=map(int,input().split()) A map(int,input().split()) map int input().split() ().split () input split B C A,B=A-1,B-1 A A-1 A 1 B B-1 B 1 dp1[A][B]=C dp1[A][B] [A] dp1 A B C dp1[B][A]=C dp1[B][A] [B] dp1 B A C floyd_warshall(dp1) floyd_warshall dp1 [INF]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF]*N [INF] INF N dp2=[[INF]*N for i in range(N)] dp2 [[INF]*N for i in range(N)] for i in range(N):
    for j in range(N):
        if i==j:
            dp2[i][j]=0
        else:
            dp2[i][j]=1 if dp1[i][j]<=L else INF i range(N) range N for j in range(N):
        if i==j:
            dp2[i][j]=0
        else:
            dp2[i][j]=1 if dp1[i][j]<=L else INF j range(N) range N if i==j:
            dp2[i][j]=0
        else:
            dp2[i][j]=1 if dp1[i][j]<=L else INF i==j i j dp2[i][j]=0 dp2[i][j] [i] dp2 i j 0 dp2[i][j]=1 if dp1[i][j]<=L else INF dp2[i][j] [i] dp2 i j 1 if dp1[i][j]<=L else INF dp1[i][j]<=L dp1[i][j] [i] dp1 i j L 1 INF floyd_warshall(dp2) floyd_warshall dp2 Q=int(input()) Q int(input()) int input() input for _ in range(Q):
    s,t=map(lambda x:int(x)-1,input().split())
    print (dp2[s][t]-1 if dp2[s][t]!=INF else -1) _ range(Q) range Q s,t=map(lambda x:int(x)-1,input().split()) s map(lambda x:int(x)-1,input().split()) map lambda x:int(x)-1 int(x)-1 int(x) int x 1 x input().split() ().split () input split t print (dp2[s][t]-1 if dp2[s][t]!=INF else -1) print dp2[s][t]-1 if dp2[s][t]!=INF else -1 dp2[s][t]!=INF dp2[s][t] [s] dp2 s t INF dp2[s][t]-1 dp2[s][t] [s] dp2 s t 1 -1 dp1=[[INF]*N for i in range(N)] [[INF]*N for i in range(N)] dp1 L=map(int,input().split()) map(int,input().split()) L A,B,C=map(int,input().split()) map(int,input().split()) A B=A-1,B-1 B-1 B input=sys.stdin.readline sys.stdin.readline input C=map(int,input().split()) map(int,input().split()) C dp2=[[INF]*N for i in range(N)] [[INF]*N for i in range(N)] dp2 B,C=map(int,input().split()) map(int,input().split()) B t=map(lambda x:int(x)-1,input().split()) map(lambda x:int(x)-1,input().split()) t M,L=map(int,input().split()) map(int,input().split()) M def floyd_warshall(G):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j]=min(G[i][j],G[i][k]+G[k][j]) def floyd_warshall(G):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j]=min(G[i][j],G[i][k]+G[k][j]) floyd_warshall INF=10**30 10**30 INF Q=int(input()) int(input()) Q s,t=map(lambda x:int(x)-1,input().split()) map(lambda x:int(x)-1,input().split()) s A,B=A-1,B-1 A-1 A N,M,L=map(int,input().split()) map(int,input().split()) N
def floyd_warshall(G):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j]=min(G[i][j],G[i][k]+G[k][j])

import sys
input=sys.stdin.readline
INF=10**30
N,M,L=map(int,input().split())
dp1=[[INF]*N for i in range(N)]
for i in range(N):
    dp1[i][i]=0
for _ in range(M):
    A,B,C=map(int,input().split())
    A,B=A-1,B-1
    dp1[A][B]=C
    dp1[B][A]=C

floyd_warshall(dp1)

dp2=[[INF]*N for i in range(N)]
for i in range(N):
    for j in range(N):
        if i==j:
            dp2[i][j]=0
        else:
            dp2[i][j]=1 if dp1[i][j]<=L else INF
floyd_warshall(dp2)

Q=int(input())
for _ in range(Q):
    s,t=map(lambda x:int(x)-1,input().split())
    print (dp2[s][t]-1 if dp2[s][t]!=INF else -1)