from scipy.sparse.csgraph import floyd_warshall

n, m, l = map(int, input().split())
inf = 10**12
d = [[inf for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(m):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
dd = floyd_warshall(d)
ddd = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
  for j in range(n):
    if dd[i][j] <= l:
      ddd[i][j] = 1
dddd =floyd_warshall(ddd)
q = int(input())
for i in range(q):
  s, t = map(int, input().split())
  if dddd[s-1][t-1] == inf:
    print(-1)
  else:
    print(int(dddd[s-1][t-1]-1)) 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 inf = 10**12 inf 10**12 10 12 [inf for i in range(n)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [inf for i in range(n)] d = [[inf for i in range(n)] for i in range(n)] d [[inf for i in range(n)] for i in range(n)] for i in range(m):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z i range(m) range m x,y,z = map(int,input().split()) x map(int,input().split()) map int input().split() ().split () input split y z d[x-1][y-1] = z d[x-1][y-1] [x-1] d x-1 x 1 y-1 y 1 z d[y-1][x-1] = z d[y-1][x-1] [y-1] d y-1 y 1 x-1 x 1 z for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０ i range(n) range n d[i][i] = 0 d[i][i] [i] d i i 0 dd = floyd_warshall(d) dd floyd_warshall(d) floyd_warshall d [inf for i in range(n)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [inf for i in range(n)] ddd = [[inf for i in range(n)] for i in range(n)] ddd [[inf for i in range(n)] for i in range(n)] for i in range(n):
  for j in range(n):
    if dd[i][j] <= l:
      ddd[i][j] = 1 i range(n) range n for j in range(n):
    if dd[i][j] <= l:
      ddd[i][j] = 1 j range(n) range n if dd[i][j] <= l:
      ddd[i][j] = 1 dd[i][j] <= l dd[i][j] [i] dd i j l ddd[i][j] = 1 ddd[i][j] [i] ddd i j 1 dddd =floyd_warshall(ddd) dddd floyd_warshall(ddd) floyd_warshall ddd q = int(input()) q int(input()) int input() input for i in range(q):
  s, t = map(int, input().split())
  if dddd[s-1][t-1] == inf:
    print(-1)
  else:
    print(int(dddd[s-1][t-1]-1)) i range(q) range q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t if dddd[s-1][t-1] == inf:
    print(-1)
  else:
    print(int(dddd[s-1][t-1]-1)) dddd[s-1][t-1] == inf dddd[s-1][t-1] [s-1] dddd s-1 s 1 t-1 t 1 inf print(-1) print -1 print(int(dddd[s-1][t-1]-1)) print int(dddd[s-1][t-1]-1) int dddd[s-1][t-1]-1 dddd[s-1][t-1] [s-1] dddd s-1 s 1 t-1 t 1 1 y,z = map(int,input().split()) map(int,input().split()) y l = map(int, input().split()) map(int, input().split()) l t = map(int, input().split()) map(int, input().split()) t m, l = map(int, input().split()) map(int, input().split()) m ddd = [[inf for i in range(n)] for i in range(n)] [[inf for i in range(n)] for i in range(n)] ddd dddd =floyd_warshall(ddd) floyd_warshall(ddd) dddd s, t = map(int, input().split()) map(int, input().split()) s dd = floyd_warshall(d) floyd_warshall(d) dd n, m, l = map(int, input().split()) map(int, input().split()) n d = [[inf for i in range(n)] for i in range(n)] [[inf for i in range(n)] for i in range(n)] d z = map(int,input().split()) map(int,input().split()) z x,y,z = map(int,input().split()) map(int,input().split()) x q = int(input()) int(input()) q inf = 10**12 10**12 inf
from scipy.sparse.csgraph import floyd_warshall

n, m, l = map(int, input().split())
inf = 10**12
d = [[inf for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(m):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
dd = floyd_warshall(d)
ddd = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
  for j in range(n):
    if dd[i][j] <= l:
      ddd[i][j] = 1
dddd =floyd_warshall(ddd)
q = int(input())
for i in range(q):
  s, t = map(int, input().split())
  if dddd[s-1][t-1] == inf:
    print(-1)
  else:
    print(int(dddd[s-1][t-1]-1))