N, M, L = map(int, input().split())
INF = 10**12
dp = [[INF]*N for i in range(N)]
fp = [[INF]*N for i in range(N)]
for i in range(N):
  dp[i][i]=0
  fp[i][i]=0
k = [[0]*N for i in range(N)]
for i in range(M):
  a, b, c = map(int, input().split())
  dp[a-1][b-1] = c
  dp[b-1][a-1] = c

for i in range(N):
  for j in range(N):
    for h in range(N):
      dp[j][h] = min(dp[j][h], dp[j][i]+dp[i][h])

for j in range(N):
  for h in range(N):
    if dp[j][h]<=L:
      fp[j][h] = 1
for i in range(N):
  for j in range(N):
    for h in range(N):
      fp[j][h] = min(fp[j][h], fp[j][i]+fp[i][h])
Q = int(input())
for i in range(Q):
  s, t = map(int, input().split())
  s = s-1
  t = t-1
  if fp[s][t]==INF:
    print(-1)
  else:
    print(fp[s][t]-1)
 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]*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 dp = [[INF]*N for i in range(N)] dp [[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 fp = [[INF]*N for i in range(N)] fp [[INF]*N for i in range(N)] for i in range(N):
  dp[i][i]=0
  fp[i][i]=0 i range(N) range N dp[i][i]=0 dp[i][i] [i] dp i i 0 fp[i][i]=0 fp[i][i] [i] fp i i 0 [0]*N for i in range(N) for i in range(N) i range(N) range N for i in range(N) [0]*N [0] 0 N k = [[0]*N for i in range(N)] k [[0]*N for i in range(N)] for i in range(M):
  a, b, c = map(int, input().split())
  dp[a-1][b-1] = c
  dp[b-1][a-1] = 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 dp[a-1][b-1] = c dp[a-1][b-1] [a-1] dp a-1 a 1 b-1 b 1 c dp[b-1][a-1] = c dp[b-1][a-1] [b-1] dp b-1 b 1 a-1 a 1 c for i in range(N):
  for j in range(N):
    for h in range(N):
      dp[j][h] = min(dp[j][h], dp[j][i]+dp[i][h]) i range(N) range N for j in range(N):
    for h in range(N):
      dp[j][h] = min(dp[j][h], dp[j][i]+dp[i][h]) j range(N) range N for h in range(N):
      dp[j][h] = min(dp[j][h], dp[j][i]+dp[i][h]) h range(N) range N dp[j][h] = min(dp[j][h], dp[j][i]+dp[i][h]) dp[j][h] [j] dp j h min(dp[j][h], dp[j][i]+dp[i][h]) min dp[j][h] [j] dp j h dp[j][i]+dp[i][h] dp[j][i] [j] dp j i dp[i][h] [i] dp i h for j in range(N):
  for h in range(N):
    if dp[j][h]<=L:
      fp[j][h] = 1 j range(N) range N for h in range(N):
    if dp[j][h]<=L:
      fp[j][h] = 1 h range(N) range N if dp[j][h]<=L:
      fp[j][h] = 1 dp[j][h]<=L dp[j][h] [j] dp j h L fp[j][h] = 1 fp[j][h] [j] fp j h 1 for i in range(N):
  for j in range(N):
    for h in range(N):
      fp[j][h] = min(fp[j][h], fp[j][i]+fp[i][h]) i range(N) range N for j in range(N):
    for h in range(N):
      fp[j][h] = min(fp[j][h], fp[j][i]+fp[i][h]) j range(N) range N for h in range(N):
      fp[j][h] = min(fp[j][h], fp[j][i]+fp[i][h]) h range(N) range N fp[j][h] = min(fp[j][h], fp[j][i]+fp[i][h]) fp[j][h] [j] fp j h min(fp[j][h], fp[j][i]+fp[i][h]) min fp[j][h] [j] fp j h fp[j][i]+fp[i][h] fp[j][i] [j] fp j i fp[i][h] [i] fp i h Q = int(input()) Q int(input()) int input() input for i in range(Q):
  s, t = map(int, input().split())
  s = s-1
  t = t-1
  if fp[s][t]==INF:
    print(-1)
  else:
    print(fp[s][t]-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 s = s-1 s s-1 s 1 t = t-1 t t-1 t 1 if fp[s][t]==INF:
    print(-1)
  else:
    print(fp[s][t]-1) fp[s][t]==INF fp[s][t] [s] fp s t INF print(-1) print -1 print(fp[s][t]-1) print fp[s][t]-1 fp[s][t] [s] fp s t 1 a, b, c = map(int, input().split()) map(int, input().split()) a b, c = map(int, input().split()) map(int, input().split()) b Q = int(input()) int(input()) Q L = map(int, input().split()) map(int, input().split()) L dp = [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] dp s, t = map(int, input().split()) map(int, input().split()) s s = s-1 s-1 s t = t-1 t-1 t N, M, L = map(int, input().split()) map(int, input().split()) N M, L = map(int, input().split()) map(int, input().split()) M k = [[0]*N for i in range(N)] [[0]*N for i in range(N)] k fp = [[INF]*N for i in range(N)] [[INF]*N for i in range(N)] fp INF = 10**12 10**12 INF t = map(int, input().split()) map(int, input().split()) t c = map(int, input().split()) map(int, input().split()) c
N, M, L = map(int, input().split())
INF = 10**12
dp = [[INF]*N for i in range(N)]
fp = [[INF]*N for i in range(N)]
for i in range(N):
  dp[i][i]=0
  fp[i][i]=0
k = [[0]*N for i in range(N)]
for i in range(M):
  a, b, c = map(int, input().split())
  dp[a-1][b-1] = c
  dp[b-1][a-1] = c

for i in range(N):
  for j in range(N):
    for h in range(N):
      dp[j][h] = min(dp[j][h], dp[j][i]+dp[i][h])

for j in range(N):
  for h in range(N):
    if dp[j][h]<=L:
      fp[j][h] = 1
for i in range(N):
  for j in range(N):
    for h in range(N):
      fp[j][h] = min(fp[j][h], fp[j][i]+fp[i][h])
Q = int(input())
for i in range(Q):
  s, t = map(int, input().split())
  s = s-1
  t = t-1
  if fp[s][t]==INF:
    print(-1)
  else:
    print(fp[s][t]-1)

