import sys
input = sys.stdin.readline

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

def main():
  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)
      
if __name__ == "__main__":
  main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline import numpy as np numpy from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix def main():
  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)
       main 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 if __name__ == "__main__":
  main() __name__ == "__main__" __name__ "__main__" main() main input = sys.stdin.readline sys.stdin.readline input def main():
  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)
       def main():
  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)
       main
import sys
input = sys.stdin.readline

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

def main():
  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)
      
if __name__ == "__main__":
  main()