#import numpy as np
from scipy.sparse.csgraph import floyd_warshall, csgraph_from_dense
from scipy.sparse import csr_matrix

N,M,L = map(int, input().split())
V = [[ 10**12 for _ in range(N) ] for _ in range(N)]
for _ in range(M):
  a,b,c = map(int, input().split())
  a,b = a-1, b-1
  V[a][b] = c
  V[b][a] = c
  
G = csgraph_from_dense(V, null_value=10**12)
d = floyd_warshall(G)

V2 = [[ 10**9 for _ in range(N) ] for _ in range(N)]
for i in range(N):
  for j in range(N):
    if 0 < d[i][j] <= L:
      V2[i][j] = 1
      
G2 = csgraph_from_dense(V2, null_value=10**9)
d2 = floyd_warshall(G2)

Q = int(input())
for _ in range(Q):
  s,t = map(int, input().split())
  s,t = s-1, t-1
  print(int(d2[s][t])-1 if d2[s][t] < 1000 else -1) from scipy.sparse.csgraph import floyd_warshall, csgraph_from_dense from scipy.sparse import csr_matrix N,M,L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [ 10**12 for _ in range(N) ] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [ 10**12 for _ in range(N) ] V = [[ 10**12 for _ in range(N) ] for _ in range(N)] V [[ 10**12 for _ in range(N) ] for _ in range(N)] for _ in range(M):
  a,b,c = map(int, input().split())
  a,b = a-1, b-1
  V[a][b] = c
  V[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 V[a][b] = c V[a][b] [a] V a b c V[b][a] = c V[b][a] [b] V b a c G = csgraph_from_dense(V, null_value=10**12) G csgraph_from_dense(V, null_value=10**12) csgraph_from_dense V null_value=10**12 null_value 10**12 10 12 d = floyd_warshall(G) d floyd_warshall(G) floyd_warshall G [ 10**9 for _ in range(N) ] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [ 10**9 for _ in range(N) ] V2 = [[ 10**9 for _ in range(N) ] for _ in range(N)] V2 [[ 10**9 for _ in range(N) ] for _ in range(N)] for i in range(N):
  for j in range(N):
    if 0 < d[i][j] <= L:
      V2[i][j] = 1
       i range(N) range N for j in range(N):
    if 0 < d[i][j] <= L:
      V2[i][j] = 1
       j range(N) range N if 0 < d[i][j] <= L:
      V2[i][j] = 1
       0 < d[i][j] <= L 0 < d[i][j] 0 d[i][j] [i] d i j L V2[i][j] = 1 V2[i][j] [i] V2 i j 1 G2 = csgraph_from_dense(V2, null_value=10**9) G2 csgraph_from_dense(V2, null_value=10**9) csgraph_from_dense V2 null_value=10**9 null_value 10**9 10 9 d2 = floyd_warshall(G2) d2 floyd_warshall(G2) floyd_warshall G2 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
  s,t = map(int, input().split())
  s,t = s-1, t-1
  print(int(d2[s][t])-1 if d2[s][t] < 1000 else -1) _ range(Q) range Q s,t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t s,t = s-1, t-1 s s-1 s 1 t t-1 t 1 print(int(d2[s][t])-1 if d2[s][t] < 1000 else -1) print int(d2[s][t])-1 if d2[s][t] < 1000 else -1 d2[s][t] < 1000 d2[s][t] [s] d2 s t 1000 int(d2[s][t])-1 int(d2[s][t]) int d2[s][t] [s] d2 s t 1 -1 b = a-1, b-1 b-1 b N,M,L = map(int, input().split()) map(int, input().split()) N L = map(int, input().split()) map(int, input().split()) L d = floyd_warshall(G) floyd_warshall(G) d G = csgraph_from_dense(V, null_value=10**12) csgraph_from_dense(V, null_value=10**12) G V = [[ 10**12 for _ in range(N) ] for _ in range(N)] [[ 10**12 for _ in range(N) ] for _ in range(N)] V d2 = floyd_warshall(G2) floyd_warshall(G2) d2 t = map(int, input().split()) map(int, input().split()) t t = s-1, t-1 t-1 t G2 = csgraph_from_dense(V2, null_value=10**9) csgraph_from_dense(V2, null_value=10**9) G2 M,L = map(int, input().split()) map(int, input().split()) M V2 = [[ 10**9 for _ in range(N) ] for _ in range(N)] [[ 10**9 for _ in range(N) ] for _ in range(N)] V2 Q = int(input()) int(input()) Q s,t = s-1, t-1 s-1 s a,b = a-1, b-1 a-1 a c = map(int, input().split()) map(int, input().split()) c b,c = map(int, input().split()) map(int, input().split()) b s,t = map(int, input().split()) map(int, input().split()) s a,b,c = map(int, input().split()) map(int, input().split()) a
#import numpy as np
from scipy.sparse.csgraph import floyd_warshall, csgraph_from_dense
from scipy.sparse import csr_matrix

N,M,L = map(int, input().split())
V = [[ 10**12 for _ in range(N) ] for _ in range(N)]
for _ in range(M):
  a,b,c = map(int, input().split())
  a,b = a-1, b-1
  V[a][b] = c
  V[b][a] = c
  
G = csgraph_from_dense(V, null_value=10**12)
d = floyd_warshall(G)

V2 = [[ 10**9 for _ in range(N) ] for _ in range(N)]
for i in range(N):
  for j in range(N):
    if 0 < d[i][j] <= L:
      V2[i][j] = 1
      
G2 = csgraph_from_dense(V2, null_value=10**9)
d2 = floyd_warshall(G2)

Q = int(input())
for _ in range(Q):
  s,t = map(int, input().split())
  s,t = s-1, t-1
  print(int(d2[s][t])-1 if d2[s][t] < 1000 else -1)
