import sys
input = sys.stdin.readline
N, M, L = map(int, input().split())
d = [[10 ** 16 * (i != j) for j in range(N + 1)] for i in range(N + 1)]
for _ in range(M):
  x, y, c = map(int, input().split())
  d[x][y] = c
  d[y][x] = c
for k in range(N + 1):
  for i in range(N + 1):
    for j in range(N + 1): d[i][j] = min(d[i][j], d[i][k] + d[k][j])

dd = [[(d[i][j] <= L) + (d[i][j] > L) * 10 ** 16 for j in range(N + 1)] for i in range(N + 1)]
for k in range(N + 1):
  for i in range(N + 1):
    for j in range(N + 1): dd[i][j] = min(dd[i][j], dd[i][k] + dd[k][j])

for _ in range(int(input())):
  s, t = map(int, input().split())
  if dd[s][t] != 10 ** 16: print(dd[s][t] - 1)
  else: print(-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 [10 ** 16 * (i != j) for j in range(N + 1)] for i in range(N + 1) for i in range(N + 1) i range(N + 1) range N + 1 N 1 for i in range(N + 1) [10 ** 16 * (i != j) for j in range(N + 1)] d = [[10 ** 16 * (i != j) for j in range(N + 1)] for i in range(N + 1)] d [[10 ** 16 * (i != j) for j in range(N + 1)] for i in range(N + 1)] for _ in range(M):
  x, y, c = map(int, input().split())
  d[x][y] = c
  d[y][x] = c _ range(M) range M x, y, c = map(int, input().split()) x map(int, input().split()) map int input().split() ().split () input split y c d[x][y] = c d[x][y] [x] d x y c d[y][x] = c d[y][x] [y] d y x c for k in range(N + 1):
  for i in range(N + 1):
    for j in range(N + 1): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) k range(N + 1) range N + 1 N 1 for i in range(N + 1):
    for j in range(N + 1): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) i range(N + 1) range N + 1 N 1 for j in range(N + 1): d[i][j] = min(d[i][j], d[i][k] + d[k] j range(N + 1) range N + 1 N 1 [(d[i][j] <= L) + (d[i][j] > L) * 10 ** 16 for j in range(N + 1)] for i in range(N + 1) for i in range(N + 1) i range(N + 1) range N + 1 N 1 for i in range(N + 1) [(d[i][j] <= L) + (d[i][j] > L) * 10 ** 16 for j in range(N + 1)] dd = [[(d[i][j] <= L) + (d[i][j] > L) * 10 ** 16 for j in range(N + 1)] for i in range(N + 1)] dd [[(d[i][j] <= L) + (d[i][j] > L) * 10 ** 16 for j in range(N + 1)] for i in range(N + 1)] for k in range(N + 1):
  for i in range(N + 1):
    for j in range(N + 1): dd[i][j] = min(dd[i][j], dd[i][k] + dd[k][j]) k range(N + 1) range N + 1 N 1 for i in range(N + 1):
    for j in range(N + 1): dd[i][j] = min(dd[i][j], dd[i][k] + dd[k][j]) i range(N + 1) range N + 1 N 1 for j in range(N + 1): dd[i][j] = min(dd[i][j], dd[i][k] + dd[k] j range(N + 1) range N + 1 N 1 for _ in range(int(input())):
  s, t = map(int, input().split())
  if dd[s][t] != 10 ** 16: print(dd[s][t] - 1)
  else: print(-1) _ range(int(input())) range int(input()) int input() input s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t if dd[s][t] != 10 ** 16: print(dd[s][t] - 1)
  else: print(-1) dd[s][t] != 10 ** 16 dd[s][t] [s] dd s t 10 ** 16 10 16 M, L = map(int, input().split()) map(int, input().split()) M input = sys.stdin.readline sys.stdin.readline input y, c = map(int, input().split()) map(int, input().split()) y dd = [[(d[i][j] <= L) + (d[i][j] > L) * 10 ** 16 for j in range(N + 1)] for i in range(N + 1)] [[(d[i][j] <= L) + (d[i][j] > L) * 10 ** 16 for j in range(N + 1)] for i in range(N + 1)] dd d = [[10 ** 16 * (i != j) for j in range(N + 1)] for i in range(N + 1)] [[10 ** 16 * (i != j) for j in range(N + 1)] for i in range(N + 1)] d s, t = map(int, input().split()) map(int, input().split()) s L = map(int, input().split()) map(int, input().split()) L t = map(int, input().split()) map(int, input().split()) t x, y, c = map(int, input().split()) map(int, input().split()) x c = map(int, input().split()) map(int, input().split()) c N, M, L = map(int, input().split()) map(int, input().split()) N
import sys
input = sys.stdin.readline
N, M, L = map(int, input().split())
d = [[10 ** 16 * (i != j) for j in range(N + 1)] for i in range(N + 1)]
for _ in range(M):
  x, y, c = map(int, input().split())
  d[x][y] = c
  d[y][x] = c
for k in range(N + 1):
  for i in range(N + 1):
    for j in range(N + 1): d[i][j] = min(d[i][j], d[i][k] + d[k][j])

dd = [[(d[i][j] <= L) + (d[i][j] > L) * 10 ** 16 for j in range(N + 1)] for i in range(N + 1)]
for k in range(N + 1):
  for i in range(N + 1):
    for j in range(N + 1): dd[i][j] = min(dd[i][j], dd[i][k] + dd[k][j])

for _ in range(int(input())):
  s, t = map(int, input().split())
  if dd[s][t] != 10 ** 16: print(dd[s][t] - 1)
  else: print(-1)