from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
INF = 10**9 + 1
dist = [[0 if i == j else INF for i in range(N+1)] for j in range(N+1)]
for i in range(M):
  a, b, c = map(int, input().split())
  dist[a][b] = c
  dist[b][a] = c

dist = floyd_warshall(dist)

dist_2 = [[INF for i in range(N+1)] for j in range(N+1)]
for i in range(1, N+1):
  for j in range(i+1, N+1):
    if dist[i][j] <= L:
      dist_2[i][j] = 1
      dist_2[j][i] = 1

dist_2 = floyd_warshall(dist_2)

Q = int(input())
for i in range(Q):
  s, t = map(int, input().split())
  print(-1 if dist_2[s][t] == INF else int(dist_2[s][t]-1)) from scipy.sparse.csgraph import floyd_warshall N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L INF = 10**9 + 1 INF 10**9 + 1 10**9 10 9 1 [0 if i == j else INF for i in range(N+1)] for j in range(N+1) for j in range(N+1) j range(N+1) range N+1 N 1 for j in range(N+1) [0 if i == j else INF for i in range(N+1)] dist = [[0 if i == j else INF for i in range(N+1)] for j in range(N+1)] dist [[0 if i == j else INF for i in range(N+1)] for j in range(N+1)] for i in range(M):
  a, b, c = map(int, input().split())
  dist[a][b] = c
  dist[b][a] = c i 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 dist[a][b] = c dist[a][b] [a] dist a b c dist[b][a] = c dist[b][a] [b] dist b a c dist = floyd_warshall(dist) dist floyd_warshall(dist) floyd_warshall dist [INF for i in range(N+1)] for j in range(N+1) for j in range(N+1) j range(N+1) range N+1 N 1 for j in range(N+1) [INF for i in range(N+1)] dist_2 = [[INF for i in range(N+1)] for j in range(N+1)] dist_2 [[INF for i in range(N+1)] for j in range(N+1)] for i in range(1, N+1):
  for j in range(i+1, N+1):
    if dist[i][j] <= L:
      dist_2[i][j] = 1
      dist_2[j][i] = 1 i range(1, N+1) range 1 N+1 N 1 for j in range(i+1, N+1):
    if dist[i][j] <= L:
      dist_2[i][j] = 1
      dist_2[j][i] = 1 j range(i+1, N+1) range i+1 i 1 N+1 N 1 if dist[i][j] <= L:
      dist_2[i][j] = 1
      dist_2[j][i] = 1 dist[i][j] <= L dist[i][j] [i] dist i j L dist_2[i][j] = 1 dist_2[i][j] [i] dist_2 i j 1 dist_2[j][i] = 1 dist_2[j][i] [j] dist_2 j i 1 dist_2 = floyd_warshall(dist_2) dist_2 floyd_warshall(dist_2) floyd_warshall dist_2 Q = int(input()) Q int(input()) int input() input for i in range(Q):
  s, t = map(int, input().split())
  print(-1 if dist_2[s][t] == INF else int(dist_2[s][t]-1)) i range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t print(-1 if dist_2[s][t] == INF else int(dist_2[s][t]-1)) print -1 if dist_2[s][t] == INF else int(dist_2[s][t]-1) dist_2[s][t] == INF dist_2[s][t] [s] dist_2 s t INF -1 int(dist_2[s][t]-1) int dist_2[s][t]-1 dist_2[s][t] [s] dist_2 s t 1 dist = [[0 if i == j else INF for i in range(N+1)] for j in range(N+1)] [[0 if i == j else INF for i in range(N+1)] for j in range(N+1)] dist s, t = map(int, input().split()) map(int, input().split()) s b, c = map(int, input().split()) map(int, input().split()) b Q = int(input()) int(input()) Q M, L = map(int, input().split()) map(int, input().split()) M L = map(int, input().split()) map(int, input().split()) L INF = 10**9 + 1 10**9 + 1 INF dist_2 = [[INF for i in range(N+1)] for j in range(N+1)] [[INF for i in range(N+1)] for j in range(N+1)] dist_2 dist_2 = floyd_warshall(dist_2) floyd_warshall(dist_2) dist_2 N, M, L = map(int, input().split()) map(int, input().split()) N c = map(int, input().split()) map(int, input().split()) c a, b, c = map(int, input().split()) map(int, input().split()) a t = map(int, input().split()) map(int, input().split()) t dist = floyd_warshall(dist) floyd_warshall(dist) dist
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
INF = 10**9 + 1
dist = [[0 if i == j else INF for i in range(N+1)] for j in range(N+1)]
for i in range(M):
  a, b, c = map(int, input().split())
  dist[a][b] = c
  dist[b][a] = c

dist = floyd_warshall(dist)

dist_2 = [[INF for i in range(N+1)] for j in range(N+1)]
for i in range(1, N+1):
  for j in range(i+1, N+1):
    if dist[i][j] <= L:
      dist_2[i][j] = 1
      dist_2[j][i] = 1

dist_2 = floyd_warshall(dist_2)

Q = int(input())
for i in range(Q):
  s, t = map(int, input().split())
  print(-1 if dist_2[s][t] == INF else int(dist_2[s][t]-1))
