import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

n,m,l = map(int, input().split())

d=[[sys.maxsize]*(n) for _ in range(n)]
e=[[sys.maxsize]*(n) for _ in range(n)]
for i in range(n):
  d[i][i] = 0
  e[i][i] = 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(csr_matrix(d))
for i in range(n):
  for j in range(n):
    if d[i][j] <= l:
      e[i][j] = 1

e=floyd_warshall(csr_matrix(e))

q=int(input())
for _ in range(q):
  s,t = map(int, input().split())
  if e[s-1][t-1] == sys.maxsize:
    print(-1)
  else:
    print(int(e[s-1][t-1]-1)) import sys sys from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall n,m,l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l [sys.maxsize]*(n) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [sys.maxsize]*(n) [sys.maxsize] sys.maxsize sys maxsize n d=[[sys.maxsize]*(n) for _ in range(n)] d [[sys.maxsize]*(n) for _ in range(n)] [sys.maxsize]*(n) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [sys.maxsize]*(n) [sys.maxsize] sys.maxsize sys maxsize n e=[[sys.maxsize]*(n) for _ in range(n)] e [[sys.maxsize]*(n) for _ in range(n)] for i in range(n):
  d[i][i] = 0
  e[i][i] = 0 i range(n) range n d[i][i] = 0 d[i][i] [i] d i i 0 e[i][i] = 0 e[i][i] [i] e i i 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] [a-1] d a-1 a 1 b-1 b 1 c d[b-1][a-1]=c d[b-1][a-1] [b-1] d b-1 b 1 a-1 a 1 c d=floyd_warshall(csr_matrix(d)) d floyd_warshall(csr_matrix(d)) floyd_warshall csr_matrix(d) csr_matrix d for i in range(n):
  for j in range(n):
    if d[i][j] <= l:
      e[i][j] = 1 i range(n) range n for j in range(n):
    if d[i][j] <= l:
      e[i][j] = 1 j range(n) range n if d[i][j] <= l:
      e[i][j] = 1 d[i][j] <= l d[i][j] [i] d i j l e[i][j] = 1 e[i][j] [i] e i j 1 e=floyd_warshall(csr_matrix(e)) e floyd_warshall(csr_matrix(e)) floyd_warshall csr_matrix(e) csr_matrix e q=int(input()) q int(input()) int input() input for _ in range(q):
  s,t = map(int, input().split())
  if e[s-1][t-1] == sys.maxsize:
    print(-1)
  else:
    print(int(e[s-1][t-1]-1)) _ range(q) range q s,t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t if e[s-1][t-1] == sys.maxsize:
    print(-1)
  else:
    print(int(e[s-1][t-1]-1)) e[s-1][t-1] == sys.maxsize e[s-1][t-1] [s-1] e s-1 s 1 t-1 t 1 sys.maxsize sys maxsize print(-1) print -1 print(int(e[s-1][t-1]-1)) print int(e[s-1][t-1]-1) int e[s-1][t-1]-1 e[s-1][t-1] [s-1] e s-1 s 1 t-1 t 1 1 s,t = map(int, input().split()) map(int, input().split()) s b,c = map(int, input().split()) map(int, input().split()) b l = map(int, input().split()) map(int, input().split()) l n,m,l = map(int, input().split()) map(int, input().split()) n c = map(int, input().split()) map(int, input().split()) c d=[[sys.maxsize]*(n) for _ in range(n)] [[sys.maxsize]*(n) for _ in range(n)] d d=floyd_warshall(csr_matrix(d)) floyd_warshall(csr_matrix(d)) d m,l = map(int, input().split()) map(int, input().split()) m e=[[sys.maxsize]*(n) for _ in range(n)] [[sys.maxsize]*(n) for _ in range(n)] e t = map(int, input().split()) map(int, input().split()) t e=floyd_warshall(csr_matrix(e)) floyd_warshall(csr_matrix(e)) e a,b,c = map(int, input().split()) map(int, input().split()) a q=int(input()) int(input()) q
import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

n,m,l = map(int, input().split())

d=[[sys.maxsize]*(n) for _ in range(n)]
e=[[sys.maxsize]*(n) for _ in range(n)]
for i in range(n):
  d[i][i] = 0
  e[i][i] = 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(csr_matrix(d))
for i in range(n):
  for j in range(n):
    if d[i][j] <= l:
      e[i][j] = 1

e=floyd_warshall(csr_matrix(e))

q=int(input())
for _ in range(q):
  s,t = map(int, input().split())
  if e[s-1][t-1] == sys.maxsize:
    print(-1)
  else:
    print(int(e[s-1][t-1]-1))