import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
n, m, l = map(int, input().split())
F = np.zeros((n, n))
for _ in range(m):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1
  F[a, b] = c
  F[b, a] = c
csr = csr_matrix(F)
A = floyd_warshall(csr)
G = np.zeros((n, n))
for i in range(n-1):
  for j in range(i+1, n):
    if A[i][j] <= l:
      G[i, j] = 1
      G[j, i] = 1
ncsr = csr_matrix(G)
B =  floyd_warshall(ncsr)
q = int(input())
for _ in range(q):
  s, t = map(int, input().split())
  k = B[s-1][t-1]
  if k == float("inf"):
    print(-1)
  else:
    print(int(k)-1) import numpy as np numpy from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l F = np.zeros((n, n)) F np.zeros((n, n)) np.zeros np zeros (n, n) n n for _ in range(m):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1
  F[a, b] = c
  F[b, a] = 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 a -= 1 a 1 b -= 1 b 1 F[a, b] = c F[a, b] F a c F[b, a] = c F[b, a] F b c csr = csr_matrix(F) csr csr_matrix(F) csr_matrix F A = floyd_warshall(csr) A floyd_warshall(csr) floyd_warshall csr G = np.zeros((n, n)) G np.zeros((n, n)) np.zeros np zeros (n, n) n n for i in range(n-1):
  for j in range(i+1, n):
    if A[i][j] <= l:
      G[i, j] = 1
      G[j, i] = 1 i range(n-1) range n-1 n 1 for j in range(i+1, n):
    if A[i][j] <= l:
      G[i, j] = 1
      G[j, i] = 1 j range(i+1, n) range i+1 i 1 n if A[i][j] <= l:
      G[i, j] = 1
      G[j, i] = 1 A[i][j] <= l A[i][j] [i] A i j l G[i, j] = 1 G[i, j] G i 1 G[j, i] = 1 G[j, i] G j 1 ncsr = csr_matrix(G) ncsr csr_matrix(G) csr_matrix G B =  floyd_warshall(ncsr) B floyd_warshall(ncsr) floyd_warshall ncsr q = int(input()) q int(input()) int input() input for _ in range(q):
  s, t = map(int, input().split())
  k = B[s-1][t-1]
  if k == float("inf"):
    print(-1)
  else:
    print(int(k)-1) _ range(q) range q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t k = B[s-1][t-1] k B[s-1][t-1] [s-1] B s-1 s 1 t-1 t 1 if k == float("inf"):
    print(-1)
  else:
    print(int(k)-1) k == float("inf") k float("inf") float "inf" print(-1) print -1 print(int(k)-1) print int(k)-1 int(k) int k 1 B =  floyd_warshall(ncsr) floyd_warshall(ncsr) B m, l = map(int, input().split()) map(int, input().split()) m c = map(int, input().split()) map(int, input().split()) c A = floyd_warshall(csr) floyd_warshall(csr) A s, t = map(int, input().split()) map(int, input().split()) s q = int(input()) int(input()) q k = B[s-1][t-1] B[s-1][t-1] k a -= 1 1 a ncsr = csr_matrix(G) csr_matrix(G) ncsr G = np.zeros((n, n)) np.zeros((n, n)) G b, c = map(int, input().split()) map(int, input().split()) b l = map(int, input().split()) map(int, input().split()) l b -= 1 1 b n, m, l = map(int, input().split()) map(int, input().split()) n a, b, c = map(int, input().split()) map(int, input().split()) a t = map(int, input().split()) map(int, input().split()) t F = np.zeros((n, n)) np.zeros((n, n)) F csr = csr_matrix(F) csr_matrix(F) csr
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
n, m, l = map(int, input().split())
F = np.zeros((n, n))
for _ in range(m):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1
  F[a, b] = c
  F[b, a] = c
csr = csr_matrix(F)
A = floyd_warshall(csr)
G = np.zeros((n, n))
for i in range(n-1):
  for j in range(i+1, n):
    if A[i][j] <= l:
      G[i, j] = 1
      G[j, i] = 1
ncsr = csr_matrix(G)
B =  floyd_warshall(ncsr)
q = int(input())
for _ in range(q):
  s, t = map(int, input().split())
  k = B[s-1][t-1]
  if k == float("inf"):
    print(-1)
  else:
    print(int(k)-1)