import sys
readline = sys.stdin.readline

import math

# 最短距離をワーシャルフロイドで求める
# 最短距離がL以下の街には燃料1で行けるので、辺を貼り直してワーシャルフロイド

N,M,L = map(int,readline().split())

import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse.csgraph import csgraph_from_dense
INF = 10 ** 9 + 1
G = [[INF for i in range(N)] for j in range(N)]
for i in range(M):
  a,b,c = map(int,readline().split())
  G[a - 1][b - 1] = c
  G[b - 1][a - 1] = c
G = csgraph_from_dense(G, null_value=INF)
d = floyd_warshall(G)

EG = [[INF for i in range(N)] for j in range(N)]
for i in range(N):
  for j in range(N):
    if d[i][j] <= L:
      EG[i][j] = 1

EG = csgraph_from_dense(EG, null_value=INF)
d = floyd_warshall(EG)

Q = int(readline())
for i in range(Q):
  s,t = map(int,readline().split())
  if d[s - 1][t - 1] != math.inf:
    print(int(d[s - 1][t - 1] - 1))
  else:
    print(-1) import sys sys readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline import math math N,M,L = map(int,readline().split()) N map(int,readline().split()) map int readline().split() ().split () readline split M L import numpy as np numpy from scipy.sparse.csgraph import shortest_path from scipy.sparse.csgraph import floyd_warshall from scipy.sparse.csgraph import csgraph_from_dense INF = 10 ** 9 + 1 INF 10 ** 9 + 1 10 ** 9 10 9 1 [INF for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [INF for i in range(N)] G = [[INF for i in range(N)] for j in range(N)] G [[INF for i in range(N)] for j in range(N)] for i in range(M):
  a,b,c = map(int,readline().split())
  G[a - 1][b - 1] = c
  G[b - 1][a - 1] = c i range(M) range M a,b,c = map(int,readline().split()) a map(int,readline().split()) map int readline().split() ().split () readline split 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 G = csgraph_from_dense(G, null_value=INF) G csgraph_from_dense(G, null_value=INF) csgraph_from_dense G null_value=INF null_value INF d = floyd_warshall(G) d floyd_warshall(G) floyd_warshall G [INF for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [INF for i in range(N)] EG = [[INF for i in range(N)] for j in range(N)] EG [[INF for i in range(N)] for j in range(N)] for i in range(N):
  for j in range(N):
    if d[i][j] <= L:
      EG[i][j] = 1 i range(N) range N for j in range(N):
    if d[i][j] <= L:
      EG[i][j] = 1 j range(N) range N if d[i][j] <= L:
      EG[i][j] = 1 d[i][j] <= L d[i][j] [i] d i j L EG[i][j] = 1 EG[i][j] [i] EG i j 1 EG = csgraph_from_dense(EG, null_value=INF) EG csgraph_from_dense(EG, null_value=INF) csgraph_from_dense EG null_value=INF null_value INF d = floyd_warshall(EG) d floyd_warshall(EG) floyd_warshall EG Q = int(readline()) Q int(readline()) int readline() readline for i in range(Q):
  s,t = map(int,readline().split())
  if d[s - 1][t - 1] != math.inf:
    print(int(d[s - 1][t - 1] - 1))
  else:
    print(-1) i range(Q) range Q s,t = map(int,readline().split()) s map(int,readline().split()) map int readline().split() ().split () readline split t if d[s - 1][t - 1] != math.inf:
    print(int(d[s - 1][t - 1] - 1))
  else:
    print(-1) d[s - 1][t - 1] != math.inf d[s - 1][t - 1] [s - 1] d s - 1 s 1 t - 1 t 1 math.inf math inf print(int(d[s - 1][t - 1] - 1)) print int(d[s - 1][t - 1] - 1) int d[s - 1][t - 1] - 1 d[s - 1][t - 1] [s - 1] d s - 1 s 1 t - 1 t 1 1 print(-1) print -1 EG = [[INF for i in range(N)] for j in range(N)] [[INF for i in range(N)] for j in range(N)] EG c = map(int,readline().split()) map(int,readline().split()) c Q = int(readline()) int(readline()) Q G = csgraph_from_dense(G, null_value=INF) csgraph_from_dense(G, null_value=INF) G readline = sys.stdin.readline sys.stdin.readline readline G = [[INF for i in range(N)] for j in range(N)] [[INF for i in range(N)] for j in range(N)] G INF = 10 ** 9 + 1 10 ** 9 + 1 INF b,c = map(int,readline().split()) map(int,readline().split()) b d = floyd_warshall(G) floyd_warshall(G) d s,t = map(int,readline().split()) map(int,readline().split()) s d = floyd_warshall(EG) floyd_warshall(EG) d a,b,c = map(int,readline().split()) map(int,readline().split()) a N,M,L = map(int,readline().split()) map(int,readline().split()) N M,L = map(int,readline().split()) map(int,readline().split()) M L = map(int,readline().split()) map(int,readline().split()) L t = map(int,readline().split()) map(int,readline().split()) t EG = csgraph_from_dense(EG, null_value=INF) csgraph_from_dense(EG, null_value=INF) EG
import sys
readline = sys.stdin.readline

import math

# 最短距離をワーシャルフロイドで求める
# 最短距離がL以下の街には燃料1で行けるので、辺を貼り直してワーシャルフロイド

N,M,L = map(int,readline().split())

import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse.csgraph import csgraph_from_dense
INF = 10 ** 9 + 1
G = [[INF for i in range(N)] for j in range(N)]
for i in range(M):
  a,b,c = map(int,readline().split())
  G[a - 1][b - 1] = c
  G[b - 1][a - 1] = c
G = csgraph_from_dense(G, null_value=INF)
d = floyd_warshall(G)

EG = [[INF for i in range(N)] for j in range(N)]
for i in range(N):
  for j in range(N):
    if d[i][j] <= L:
      EG[i][j] = 1

EG = csgraph_from_dense(EG, null_value=INF)
d = floyd_warshall(EG)

Q = int(readline())
for i in range(Q):
  s,t = map(int,readline().split())
  if d[s - 1][t - 1] != math.inf:
    print(int(d[s - 1][t - 1] - 1))
  else:
    print(-1)