import sys
input = sys.stdin.readline
N,M,L = map(int, input().split())
INF = float("inf")
dist1 = [[INF]*N for i in range(N)]
dist2 = [[INF]*N for i in range(N)]

for i in range(M):
  A,B,C = map(int, input().split())
  A -= 1
  B -= 1
  dist1[A][B] = C
  dist1[B][A] = C

for i in range(N):
  dist1[i][i] = 0
  dist2[i][i] = 0
  
for k in range(N):
  for i in range(N):
    for j in range(N):
      d = dist1[i][k]+dist1[k][j]
      if dist1[i][j] <= d:
        continue
      dist1[i][j] = d
for i in range(N):
  for j in range(N):
    if dist1[i][j] > L or i==j:
      continue
    dist2[i][j] = 1
  
for k in range(N):
  for i in range(N):
    for j in range(N):
      d = dist2[i][k]+dist2[k][j]
      if dist2[i][j] <= d:
        continue
      dist2[i][j] = d
Q = int(input())
for i in range(Q):
  s,t = map(int, input().split())
  print(dist2[s-1][t-1]-1 if dist2[s-1][t-1]<=L else -1) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N,M,L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L INF = float("inf") INF float("inf") float "inf" [INF]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF]*N [INF] INF N dist1 = [[INF]*N for i in range(N)] dist1 [[INF]*N for i in range(N)] [INF]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [INF]*N [INF] INF N dist2 = [[INF]*N for i in range(N)] dist2 [[INF]*N for i in range(N)] for i in range(M):
  A,B,C = map(int, input().split())
  A -= 1
  B -= 1
  dist1[A][B] = C
  dist1[B][A] = C i 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 dist1[A][B] = C dist1[A][B] [A] dist1 A B C dist1[B][A] = C dist1[B][A] [B] dist1 B A C for i in range(N):
  dist1[i][i] = 0
  dist2[i][i] = 0
   i range(N) range N dist1[i][i] = 0 dist1[i][i] [i] dist1 i i 0 dist2[i][i] = 0 dist2[i][i] [i] dist2 i i 0 for k in range(N):
  for i in range(N):
    for j in range(N):
      d = dist1[i][k]+dist1[k][j]
      if dist1[i][j] <= d:
        continue
      dist1[i][j] = d k range(N) range N for i in range(N):
    for j in range(N):
      d = dist1[i][k]+dist1[k][j]
      if dist1[i][j] <= d:
        continue
      dist1[i][j] = d i range(N) range N for j in range(N):
      d = dist1[i][k]+dist1[k][j]
      if dist1[i][j] <= d:
        continue
      dist1[i][j] = d j range(N) range N d = dist1[i][k]+dist1[k][j] d dist1[i][k]+dist1[k][j] dist1[i][k] [i] dist1 i k dist1[k][j] [k] dist1 k j if dist1[i][j] <= d:
        continue
       dist1[i][j] <= d dist1[i][j] [i] dist1 i j d continue dist1[i][j] = d dist1[i][j] [i] dist1 i j d for i in range(N):
  for j in range(N):
    if dist1[i][j] > L or i==j:
      continue
    dist2[i][j] = 1
   i range(N) range N for j in range(N):
    if dist1[i][j] > L or i==j:
      continue
    dist2[i][j] = 1
   j range(N) range N if dist1[i][j] > L or i==j:
      continue
     dist1[i][j] > L or i==j dist1[i][j] > L dist1[i][j] [i] dist1 i j L i==j i j continue dist2[i][j] = 1 dist2[i][j] [i] dist2 i j 1 for k in range(N):
  for i in range(N):
    for j in range(N):
      d = dist2[i][k]+dist2[k][j]
      if dist2[i][j] <= d:
        continue
      dist2[i][j] = d k range(N) range N for i in range(N):
    for j in range(N):
      d = dist2[i][k]+dist2[k][j]
      if dist2[i][j] <= d:
        continue
      dist2[i][j] = d i range(N) range N for j in range(N):
      d = dist2[i][k]+dist2[k][j]
      if dist2[i][j] <= d:
        continue
      dist2[i][j] = d j range(N) range N d = dist2[i][k]+dist2[k][j] d dist2[i][k]+dist2[k][j] dist2[i][k] [i] dist2 i k dist2[k][j] [k] dist2 k j if dist2[i][j] <= d:
        continue
       dist2[i][j] <= d dist2[i][j] [i] dist2 i j d continue dist2[i][j] = d dist2[i][j] [i] dist2 i j d Q = int(input()) Q int(input()) int input() input for i in range(Q):
  s,t = map(int, input().split())
  print(dist2[s-1][t-1]-1 if dist2[s-1][t-1]<=L else -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 print(dist2[s-1][t-1]-1 if dist2[s-1][t-1]<=L else -1) print dist2[s-1][t-1]-1 if dist2[s-1][t-1]<=L else -1 dist2[s-1][t-1]<=L dist2[s-1][t-1] [s-1] dist2 s-1 s 1 t-1 t 1 L dist2[s-1][t-1]-1 dist2[s-1][t-1] [s-1] dist2 s-1 s 1 t-1 t 1 1 -1 t = map(int, input().split()) map(int, input().split()) t input = sys.stdin.readline sys.stdin.readline input s,t = map(int, input().split()) map(int, input().split()) s M,L = map(int, input().split()) map(int, input().split()) M N,M,L = map(int, input().split()) map(int, input().split()) N C = map(int, input().split()) map(int, input().split()) C A,B,C = map(int, input().split()) map(int, input().split()) A dist2 = [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] dist2 d = dist1[i][k]+dist1[k][j] dist1[i][k]+dist1[k][j] d Q = int(input()) int(input()) Q dist1 = [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] dist1 L = map(int, input().split()) map(int, input().split()) L INF = float("inf") float("inf") INF B,C = map(int, input().split()) map(int, input().split()) B B -= 1 1 B A -= 1 1 A d = dist2[i][k]+dist2[k][j] dist2[i][k]+dist2[k][j] d
import sys
input = sys.stdin.readline
N,M,L = map(int, input().split())
INF = float("inf")
dist1 = [[INF]*N for i in range(N)]
dist2 = [[INF]*N for i in range(N)]

for i in range(M):
  A,B,C = map(int, input().split())
  A -= 1
  B -= 1
  dist1[A][B] = C
  dist1[B][A] = C

for i in range(N):
  dist1[i][i] = 0
  dist2[i][i] = 0
  
for k in range(N):
  for i in range(N):
    for j in range(N):
      d = dist1[i][k]+dist1[k][j]
      if dist1[i][j] <= d:
        continue
      dist1[i][j] = d
for i in range(N):
  for j in range(N):
    if dist1[i][j] > L or i==j:
      continue
    dist2[i][j] = 1
  
for k in range(N):
  for i in range(N):
    for j in range(N):
      d = dist2[i][k]+dist2[k][j]
      if dist2[i][j] <= d:
        continue
      dist2[i][j] = d
Q = int(input())
for i in range(Q):
  s,t = map(int, input().split())
  print(dist2[s-1][t-1]-1 if dist2[s-1][t-1]<=L else -1)