from scipy.sparse.csgraph import floyd_warshall
import numpy as np

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

D = np.ones([N, N]) * np.inf
D[np.eye(N, dtype=bool)] = 0

for _ in range(M):
  A, B, C = map(int, input().split())
  D[A-1, B-1] = C
  D[B-1, A-1] = C

D = floyd_warshall(D)
D2 = (D<=L)*1.0 # boolean -> float
D2[D2==0] = np.inf
# D2 = (D <= L) + (D > L)*np.inf

D2 = floyd_warshall(D2) - 1

Q = int(input())
for _ in range(Q):
  s, t = map(int, input().split())
  r = D2[s-1, t-1]
  if r < np.inf:
    print(int(r))
  else:
    print(-1) from scipy.sparse.csgraph import floyd_warshall import numpy as np numpy N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L D = np.ones([N, N]) * np.inf D np.ones([N, N]) * np.inf np.ones([N, N]) np.ones np ones [N, N] N N np.inf np inf D[np.eye(N, dtype=bool)] = 0 D[np.eye(N, dtype=bool)] D np.eye(N, dtype=bool) np.eye np eye N dtype=bool dtype bool 0 for _ in range(M):
  A, B, C = map(int, input().split())
  D[A-1, B-1] = C
  D[B-1, A-1] = 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 D[A-1, B-1] = C D[A-1, B-1] D A-1 A 1 C D[B-1, A-1] = C D[B-1, A-1] D B-1 B 1 C D = floyd_warshall(D) D floyd_warshall(D) floyd_warshall D D2 = (D<=L)*1.0 D2 (D<=L)*1.0 D<=L D L 1.0 D2[D2==0] = np.inf D2[D2==0] D2 D2==0 D2 0 np.inf np inf D2 = floyd_warshall(D2) - 1 D2 floyd_warshall(D2) - 1 floyd_warshall(D2) floyd_warshall D2 1 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
  s, t = map(int, input().split())
  r = D2[s-1, t-1]
  if r < np.inf:
    print(int(r))
  else:
    print(-1) _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t r = D2[s-1, t-1] r D2[s-1, t-1] D2 s-1 s 1 if r < np.inf:
    print(int(r))
  else:
    print(-1) r < np.inf r np.inf np inf print(int(r)) print int(r) int r print(-1) print -1 r = D2[s-1, t-1] D2[s-1, t-1] r A, B, C = map(int, input().split()) map(int, input().split()) A Q = int(input()) int(input()) Q B, C = map(int, input().split()) map(int, input().split()) B D2 = (D<=L)*1.0 (D<=L)*1.0 D2 D2 = floyd_warshall(D2) - 1 floyd_warshall(D2) - 1 D2 N, M, L = map(int, input().split()) map(int, input().split()) N t = map(int, input().split()) map(int, input().split()) t s, t = map(int, input().split()) map(int, input().split()) s D = floyd_warshall(D) floyd_warshall(D) D D = np.ones([N, N]) * np.inf np.ones([N, N]) * np.inf D C = map(int, input().split()) map(int, input().split()) C L = map(int, input().split()) map(int, input().split()) L M, L = map(int, input().split()) map(int, input().split()) M
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

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

D = np.ones([N, N]) * np.inf
D[np.eye(N, dtype=bool)] = 0

for _ in range(M):
  A, B, C = map(int, input().split())
  D[A-1, B-1] = C
  D[B-1, A-1] = C

D = floyd_warshall(D)
D2 = (D<=L)*1.0 # boolean -> float
D2[D2==0] = np.inf
# D2 = (D <= L) + (D > L)*np.inf

D2 = floyd_warshall(D2) - 1

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