import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

f=lambda:map(int,input().split())
N,M,L=f()
G=[[0]*N for _ in [0]*N]
for _ in [0]*M:
    a,b,c=f()
    G[a-1][b-1]=c
    G[b-1][a-1]=c
    
csr=csr_matrix(G)

D=floyd_warshall(csr)
INF=float('inf')
G=[[INF]*N for _ in [0]*N]
for i in range(N):
    for j in range(N):
        if i!=j and D[i][j]<=L:
            G[i][j]=1
            G[j][i]=1
csr=csr_matrix(G)
res=floyd_warshall(csr)
Q=int(input())
for _ in [0]*Q:
    s,t=f()
    r=res[s-1][t-1]
    print(int(r-1) if r<INF else -1) import numpy as np numpy from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson from scipy.sparse import csr_matrix f=lambda:map(int,input().split()) f lambda:map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split N,M,L=f() N f() f M L [0]*N for _ in [0]*N for _ in [0]*N _ [0]*N [0] 0 N for _ in [0]*N [0]*N [0] 0 N G=[[0]*N for _ in [0]*N] G [[0]*N for _ in [0]*N] for _ in [0]*M:
    a,b,c=f()
    G[a-1][b-1]=c
    G[b-1][a-1]=c
     _ [0]*M [0] 0 M a,b,c=f() a f() f b c G[a-1][b-1]=c G[a-1][b-1] [a-1] G a-1 a 1 b-1 b 1 c G[b-1][a-1]=c G[b-1][a-1] [b-1] G b-1 b 1 a-1 a 1 c csr=csr_matrix(G) csr csr_matrix(G) csr_matrix G D=floyd_warshall(csr) D floyd_warshall(csr) floyd_warshall csr INF=float('inf') INF float('inf') float 'inf' [INF]*N for _ in [0]*N for _ in [0]*N _ [0]*N [0] 0 N for _ in [0]*N [INF]*N [INF] INF N G=[[INF]*N for _ in [0]*N] G [[INF]*N for _ in [0]*N] for i in range(N):
    for j in range(N):
        if i!=j and D[i][j]<=L:
            G[i][j]=1
            G[j][i]=1 i range(N) range N for j in range(N):
        if i!=j and D[i][j]<=L:
            G[i][j]=1
            G[j][i]=1 j range(N) range N if i!=j and D[i][j]<=L:
            G[i][j]=1
            G[j][i]=1 i!=j and D[i][j]<=L i!=j i j D[i][j]<=L D[i][j] [i] D i j L G[i][j]=1 G[i][j] [i] G i j 1 G[j][i]=1 G[j][i] [j] G j i 1 csr=csr_matrix(G) csr csr_matrix(G) csr_matrix G res=floyd_warshall(csr) res floyd_warshall(csr) floyd_warshall csr Q=int(input()) Q int(input()) int input() input for _ in [0]*Q:
    s,t=f()
    r=res[s-1][t-1]
    print(int(r-1) if r<INF else -1) _ [0]*Q [0] 0 Q s,t=f() s f() f t r=res[s-1][t-1] r res[s-1][t-1] [s-1] res s-1 s 1 t-1 t 1 print(int(r-1) if r<INF else -1) print int(r-1) if r<INF else -1 r<INF r INF int(r-1) int r-1 r 1 -1 G=[[INF]*N for _ in [0]*N] [[INF]*N for _ in [0]*N] G D=floyd_warshall(csr) floyd_warshall(csr) D res=floyd_warshall(csr) floyd_warshall(csr) res c=f() f() c b,c=f() f() b Q=int(input()) int(input()) Q f=lambda:map(int,input().split()) lambda:map(int,input().split()) f L=f() f() L csr=csr_matrix(G) csr_matrix(G) csr a,b,c=f() f() a t=f() f() t r=res[s-1][t-1] res[s-1][t-1] r s,t=f() f() s G=[[0]*N for _ in [0]*N] [[0]*N for _ in [0]*N] G csr=csr_matrix(G) csr_matrix(G) csr N,M,L=f() f() N INF=float('inf') float('inf') INF M,L=f() f() M
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

f=lambda:map(int,input().split())
N,M,L=f()
G=[[0]*N for _ in [0]*N]
for _ in [0]*M:
    a,b,c=f()
    G[a-1][b-1]=c
    G[b-1][a-1]=c
    
csr=csr_matrix(G)

D=floyd_warshall(csr)
INF=float('inf')
G=[[INF]*N for _ in [0]*N]
for i in range(N):
    for j in range(N):
        if i!=j and D[i][j]<=L:
            G[i][j]=1
            G[j][i]=1
csr=csr_matrix(G)
res=floyd_warshall(csr)
Q=int(input())
for _ in [0]*Q:
    s,t=f()
    r=res[s-1][t-1]
    print(int(r-1) if r<INF else -1)