from scipy.sparse.csgraph import floyd_warshall
N,M,L,*X = map(int, open(0).read().split())
ls = X[:3*M]
Els = [[0]*N for i in range(N)]
Q = X[3*M]
query = X[3*M+1:]
for a,b,c in zip(*[iter(ls)]*3):
  if c<=L:
    Els[a-1][b-1] = c
    Els[b-1][a-1] = c
dist = floyd_warshall(Els)
      
Els2 = [[1 if dist[i][j]<=L else 0 for j in range(N)] for i in range(N)]
ans = floyd_warshall(Els2)

for s,t in zip(*[iter(query)]*2):
  if ans[s-1][t-1]==float('inf'):
    print(-1)
    continue
  print(int(ans[s-1][t-1])-1) from scipy.sparse.csgraph import floyd_warshall N,M,L,*X = map(int, open(0).read().split()) N map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split M L *X X ls = X[:3*M] ls X[:3*M] X :3*M 3*M 3 M [0]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [0]*N [0] 0 N Els = [[0]*N for i in range(N)] Els [[0]*N for i in range(N)] Q = X[3*M] Q X[3*M] X 3*M 3 M query = X[3*M+1:] query X[3*M+1:] X 3*M+1: 3*M+1 3*M 3 M 1 for a,b,c in zip(*[iter(ls)]*3):
  if c<=L:
    Els[a-1][b-1] = c
    Els[b-1][a-1] = c a b c zip(*[iter(ls)]*3) zip *[iter(ls)]*3 [iter(ls)]*3 [iter(ls)] iter(ls) iter ls 3 if c<=L:
    Els[a-1][b-1] = c
    Els[b-1][a-1] = c c<=L c L Els[a-1][b-1] = c Els[a-1][b-1] [a-1] Els a-1 a 1 b-1 b 1 c Els[b-1][a-1] = c Els[b-1][a-1] [b-1] Els b-1 b 1 a-1 a 1 c dist = floyd_warshall(Els) dist floyd_warshall(Els) floyd_warshall Els [1 if dist[i][j]<=L else 0 for j in range(N)] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [1 if dist[i][j]<=L else 0 for j in range(N)] Els2 = [[1 if dist[i][j]<=L else 0 for j in range(N)] for i in range(N)] Els2 [[1 if dist[i][j]<=L else 0 for j in range(N)] for i in range(N)] ans = floyd_warshall(Els2) ans floyd_warshall(Els2) floyd_warshall Els2 for s,t in zip(*[iter(query)]*2):
  if ans[s-1][t-1]==float('inf'):
    print(-1)
    continue
  print(int(ans[s-1][t-1])-1) s t zip(*[iter(query)]*2) zip *[iter(query)]*2 [iter(query)]*2 [iter(query)] iter(query) iter query 2 if ans[s-1][t-1]==float('inf'):
    print(-1)
    continue
   ans[s-1][t-1]==float('inf') ans[s-1][t-1] [s-1] ans s-1 s 1 t-1 t 1 float('inf') float 'inf' print(-1) print -1 continue print(int(ans[s-1][t-1])-1) print int(ans[s-1][t-1])-1 int(ans[s-1][t-1]) int ans[s-1][t-1] [s-1] ans s-1 s 1 t-1 t 1 1 Els2 = [[1 if dist[i][j]<=L else 0 for j in range(N)] for i in range(N)] [[1 if dist[i][j]<=L else 0 for j in range(N)] for i in range(N)] Els2 ans = floyd_warshall(Els2) floyd_warshall(Els2) ans Q = X[3*M] X[3*M] Q query = X[3*M+1:] X[3*M+1:] query N,M,L,*X = map(int, open(0).read().split()) map(int, open(0).read().split()) N ls = X[:3*M] X[:3*M] ls M,L,*X = map(int, open(0).read().split()) map(int, open(0).read().split()) M L,*X = map(int, open(0).read().split()) map(int, open(0).read().split()) L Els = [[0]*N for i in range(N)] [[0]*N for i in range(N)] Els dist = floyd_warshall(Els) floyd_warshall(Els) dist
from scipy.sparse.csgraph import floyd_warshall
N,M,L,*X = map(int, open(0).read().split())
ls = X[:3*M]
Els = [[0]*N for i in range(N)]
Q = X[3*M]
query = X[3*M+1:]
for a,b,c in zip(*[iter(ls)]*3):
  if c<=L:
    Els[a-1][b-1] = c
    Els[b-1][a-1] = c
dist = floyd_warshall(Els)
      
Els2 = [[1 if dist[i][j]<=L else 0 for j in range(N)] for i in range(N)]
ans = floyd_warshall(Els2)

for s,t in zip(*[iter(query)]*2):
  if ans[s-1][t-1]==float('inf'):
    print(-1)
    continue
  print(int(ans[s-1][t-1])-1)