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

D2 = floyd_warshall(D2)

Q = int(input())
for _ in range(Q):
  s, t = map(int, input().split())
  r = D2[s-1, t-1] - 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 D2 D <= L D L D2 = floyd_warshall(D2) D2 floyd_warshall(D2) floyd_warshall D2 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] - 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] - 1 r D2[s-1, t-1] - 1 D2[s-1, t-1] D2 s-1 s 1 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 B, C = map(int, input().split()) map(int, input().split()) B D = np.ones([N, N]) * np.inf np.ones([N, N]) * np.inf D t = map(int, input().split()) map(int, input().split()) t D2 = D <= L D <= L D2 A, B, C = map(int, input().split()) map(int, input().split()) A D2 = floyd_warshall(D2) floyd_warshall(D2) D2 D = floyd_warshall(D) floyd_warshall(D) D C = map(int, input().split()) map(int, input().split()) C Q = int(input()) int(input()) Q N, M, L = map(int, input().split()) map(int, input().split()) N L = map(int, input().split()) map(int, input().split()) L s, t = map(int, input().split()) map(int, input().split()) s r = D2[s-1, t-1] - 1 D2[s-1, t-1] - 1 r 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

D2 = floyd_warshall(D2)

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

