N, M, L = map(int, input().split())
D = [[1000000000000]*N for i in range(N)]
for i in range(N):
  D[i][i] = 0
for i in range(M):
  A, B, C = map(int, input().split())
  A, B = A-1, B-1
  D[A][B] = C
  D[B][A] = C
for k in range(N):
  for i in range(N):
    for j in range(N):
      D[i][j] = min(D[i][j], D[i][k]+D[k][j])
E = [[1000000000000]*N for i in range(N)]
for i in range(N):
  E[i][i] = 0
for i in range(N):
  for j in range(N):
    if D[i][j] <= L:
      E[i][j] = 1
for k in range(N):
  for i in range(N):
    for j in range(N):
      E[i][j] = min(E[i][j], E[i][k]+E[k][j])
Q = int(input())
for i in range(Q):
  s, t = map(int, input().split())
  s, t = s-1, t-1
  if E[s][t] == 1000000000000:
    r = -1
  else:
    r = E[s][t]-1
  print(r) N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [1000000000000]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [1000000000000]*N [1000000000000] 1000000000000 N D = [[1000000000000]*N for i in range(N)] D [[1000000000000]*N for i in range(N)] 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 for i in range(M):
  A, B, C = map(int, input().split())
  A, B = A-1, B-1
  D[A][B] = C
  D[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, B = A-1, B-1 A A-1 A 1 B B-1 B 1 D[A][B] = C D[A][B] [A] D A B C D[B][A] = C D[B][A] [B] D B A C for k in range(N):
  for i in range(N):
    for j in range(N):
      D[i][j] = min(D[i][j], D[i][k]+D[k][j]) k range(N) range N for i in range(N):
    for j in range(N):
      D[i][j] = min(D[i][j], D[i][k]+D[k][j]) i range(N) range N for j in range(N):
      D[i][j] = min(D[i][j], D[i][k]+D[k][j]) j range(N) range N D[i][j] = min(D[i][j], D[i][k]+D[k][j]) D[i][j] [i] D i j min(D[i][j], D[i][k]+D[k][j]) min D[i][j] [i] D i j D[i][k]+D[k][j] D[i][k] [i] D i k D[k][j] [k] D k j [1000000000000]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [1000000000000]*N [1000000000000] 1000000000000 N E = [[1000000000000]*N for i in range(N)] E [[1000000000000]*N for i in range(N)] for i in range(N):
  E[i][i] = 0 i range(N) range N E[i][i] = 0 E[i][i] [i] E i i 0 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 for k in range(N):
  for i in range(N):
    for j in range(N):
      E[i][j] = min(E[i][j], E[i][k]+E[k][j]) k range(N) range N for i in range(N):
    for j in range(N):
      E[i][j] = min(E[i][j], E[i][k]+E[k][j]) i range(N) range N for j in range(N):
      E[i][j] = min(E[i][j], E[i][k]+E[k][j]) j range(N) range N E[i][j] = min(E[i][j], E[i][k]+E[k][j]) E[i][j] [i] E i j min(E[i][j], E[i][k]+E[k][j]) min E[i][j] [i] E i j E[i][k]+E[k][j] E[i][k] [i] E i k E[k][j] [k] E k j Q = int(input()) Q int(input()) int input() input for i in range(Q):
  s, t = map(int, input().split())
  s, t = s-1, t-1
  if E[s][t] == 1000000000000:
    r = -1
  else:
    r = E[s][t]-1
  print(r) i range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t s, t = s-1, t-1 s s-1 s 1 t t-1 t 1 if E[s][t] == 1000000000000:
    r = -1
  else:
    r = E[s][t]-1
   E[s][t] == 1000000000000 E[s][t] [s] E s t 1000000000000 r = -1 r -1 r = E[s][t]-1 r E[s][t]-1 E[s][t] [s] E s t 1 print(r) print r B = A-1, B-1 B-1 B t = s-1, t-1 t-1 t B, C = map(int, input().split()) map(int, input().split()) B A, B = A-1, B-1 A-1 A s, t = s-1, t-1 s-1 s A, B, C = map(int, input().split()) map(int, input().split()) A Q = int(input()) int(input()) Q s, t = map(int, input().split()) map(int, input().split()) s t = map(int, input().split()) map(int, input().split()) t r = -1 -1 r M, L = map(int, input().split()) map(int, input().split()) M L = map(int, input().split()) map(int, input().split()) L E = [[1000000000000]*N for i in range(N)] [[1000000000000]*N for i in range(N)] E C = map(int, input().split()) map(int, input().split()) C r = E[s][t]-1 E[s][t]-1 r N, M, L = map(int, input().split()) map(int, input().split()) N D = [[1000000000000]*N for i in range(N)] [[1000000000000]*N for i in range(N)] D
N, M, L = map(int, input().split())
D = [[1000000000000]*N for i in range(N)]
for i in range(N):
  D[i][i] = 0
for i in range(M):
  A, B, C = map(int, input().split())
  A, B = A-1, B-1
  D[A][B] = C
  D[B][A] = C
for k in range(N):
  for i in range(N):
    for j in range(N):
      D[i][j] = min(D[i][j], D[i][k]+D[k][j])
E = [[1000000000000]*N for i in range(N)]
for i in range(N):
  E[i][i] = 0
for i in range(N):
  for j in range(N):
    if D[i][j] <= L:
      E[i][j] = 1
for k in range(N):
  for i in range(N):
    for j in range(N):
      E[i][j] = min(E[i][j], E[i][k]+E[k][j])
Q = int(input())
for i in range(Q):
  s, t = map(int, input().split())
  s, t = s-1, t-1
  if E[s][t] == 1000000000000:
    r = -1
  else:
    r = E[s][t]-1
  print(r)
