import sys
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
INF = 10 **9 +1
G = [[float('inf')] * N for i in range(N)]
for i in range(M):
  a, b, c = map(int, input().split())
  a, b, = a - 1, b -1
  G[a][b] = c
  G[b][a] = c

#全点間最短距離を計算
G = floyd_warshall(G)


#コストL以下で移動可能な頂点間のコスト1の辺を張る
E = [[float('inf')] * N for i in range(N)]
for i in range(N):
  for j in range(N):
    if G[i][j] <= L:
      E[i][j] = 1

#全点間最短距離を計算
E = floyd_warshall(E)

#クエリに答えていく
Q = int(input())
for i in range(Q):
  s, t = map(int, input().split())
  s, t = s - 1, t-1
  print(int(E[s][t] - 1) if E[s][t] != float('inf') else -1) import sys sys 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 [float('inf')] * N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [float('inf')] * N [float('inf')] float('inf') float 'inf' N G = [[float('inf')] * N for i in range(N)] G [[float('inf')] * N for i in range(N)] for i in range(M):
  a, b, c = map(int, input().split())
  a, b, = a - 1, b -1
  G[a][b] = c
  G[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 a, b, = a - 1, b -1 a a - 1 a 1 b b -1 b 1 G[a][b] = c G[a][b] [a] G a b c G[b][a] = c G[b][a] [b] G b a c G = floyd_warshall(G) G floyd_warshall(G) floyd_warshall G [float('inf')] * N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [float('inf')] * N [float('inf')] float('inf') float 'inf' N E = [[float('inf')] * N for i in range(N)] E [[float('inf')] * N for i in range(N)] for i in range(N):
  for j in range(N):
    if G[i][j] <= L:
      E[i][j] = 1

#全点間最短距離を計算 i range(N) range N for j in range(N):
    if G[i][j] <= L:
      E[i][j] = 1

#全点間最短距離を計算 j range(N) range N if G[i][j] <= L:
      E[i][j] = 1

#全点間最短距離を計算 G[i][j] <= L G[i][j] [i] G i j L E[i][j] = 1 E[i][j] [i] E i j 1 E = floyd_warshall(E) E floyd_warshall(E) floyd_warshall E Q = int(input()) Q int(input()) int input() input for i in range(Q):
  s, t = map(int, input().split())
  s, t = s - 1, t-1
  print(int(E[s][t] - 1) if E[s][t] != float('inf') else -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 s, t = s - 1, t-1 s s - 1 s 1 t t-1 t 1 print(int(E[s][t] - 1) if E[s][t] != float('inf') else -1) print int(E[s][t] - 1) if E[s][t] != float('inf') else -1 E[s][t] != float('inf') E[s][t] [s] E s t float('inf') float 'inf' int(E[s][t] - 1) int E[s][t] - 1 E[s][t] [s] E s t 1 -1 E = floyd_warshall(E) floyd_warshall(E) E G = [[float('inf')] * N for i in range(N)] [[float('inf')] * N for i in range(N)] G s, t = s - 1, t-1 s - 1 s INF = 10 **9 +1 10 **9 +1 INF b, c = map(int, input().split()) map(int, input().split()) b G = floyd_warshall(G) floyd_warshall(G) G 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 s, t = map(int, input().split()) map(int, input().split()) s t = s - 1, t-1 t-1 t N, M, L = map(int, input().split()) map(int, input().split()) N a, b, c = map(int, input().split()) map(int, input().split()) a a, b, = a - 1, b -1 a - 1 a b, = a - 1, b -1 b -1 b t = map(int, input().split()) map(int, input().split()) t E = [[float('inf')] * N for i in range(N)] [[float('inf')] * N for i in range(N)] E c = map(int, input().split()) map(int, input().split()) c
import sys
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
INF = 10 **9 +1
G = [[float('inf')] * N for i in range(N)]
for i in range(M):
  a, b, c = map(int, input().split())
  a, b, = a - 1, b -1
  G[a][b] = c
  G[b][a] = c

#全点間最短距離を計算
G = floyd_warshall(G)


#コストL以下で移動可能な頂点間のコスト1の辺を張る
E = [[float('inf')] * N for i in range(N)]
for i in range(N):
  for j in range(N):
    if G[i][j] <= L:
      E[i][j] = 1

#全点間最短距離を計算
E = floyd_warshall(E)

#クエリに答えていく
Q = int(input())
for i in range(Q):
  s, t = map(int, input().split())
  s, t = s - 1, t-1
  print(int(E[s][t] - 1) if E[s][t] != float('inf') else -1)