import math
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N, M, L = IL()
abc = [IL() for _ in range(M)]
Q = I()
q = [IL() for _ in range(Q)]

dp1 = [[MAX_INT]*N for _ in range(N)]
for a, b, c in abc:
  dp1[a - 1][b - 1] = c
  dp1[b - 1][a - 1] = c

for k in range(N):
  for i in range(N):
    for j in range(N):
      if i == j:
        dp1[i][j] = 0
      else:
        dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k][j])

dp2 = [[MAX_INT]*N for _ in range(N)]
for i in range(N):
  for j in range(N):
    if dp1[i][j] <= L:
      dp2[i][j] = 1

for k in range(N):
  for i in range(N):
    for j in range(N):
      if i == j:
        dp2[i][j] = 0
      else:
        dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j])

for s, t in q:
  if dp2[s - 1][t - 1] == MAX_INT:
    print(-1)
  else:
    print(dp2[s - 1][t - 1] - 1) import math math import sys sys MAX_INT = int(10e10) MAX_INT int(10e10) int 10e10 MIN_INT = -MAX_INT MIN_INT -MAX_INT MAX_INT mod = 1000000007 mod 1000000007 sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 def IL(): return list(map(int,input().split())) IL def SL(): return input().split() SL def I(): return int(sys.stdin.readline()) I def S(): return input() S N, M, L = IL() N IL() IL M L IL() for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) IL() IL abc = [IL() for _ in range(M)] abc [IL() for _ in range(M)] Q = I() Q I() I IL() for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) IL() IL q = [IL() for _ in range(Q)] q [IL() for _ in range(Q)] [MAX_INT]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [MAX_INT]*N [MAX_INT] MAX_INT N dp1 = [[MAX_INT]*N for _ in range(N)] dp1 [[MAX_INT]*N for _ in range(N)] for a, b, c in abc:
  dp1[a - 1][b - 1] = c
  dp1[b - 1][a - 1] = c a b c abc dp1[a - 1][b - 1] = c dp1[a - 1][b - 1] [a - 1] dp1 a - 1 a 1 b - 1 b 1 c dp1[b - 1][a - 1] = c dp1[b - 1][a - 1] [b - 1] dp1 b - 1 b 1 a - 1 a 1 c for k in range(N):
  for i in range(N):
    for j in range(N):
      if i == j:
        dp1[i][j] = 0
      else:
        dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k][j]) k range(N) range N for i in range(N):
    for j in range(N):
      if i == j:
        dp1[i][j] = 0
      else:
        dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k][j]) i range(N) range N for j in range(N):
      if i == j:
        dp1[i][j] = 0
      else:
        dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k][j]) j range(N) range N if i == j:
        dp1[i][j] = 0
      else:
        dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k][j]) i == j i j dp1[i][j] = 0 dp1[i][j] [i] dp1 i j 0 dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k][j]) dp1[i][j] [i] dp1 i j min(dp1[i][j], dp1[i][k] + dp1[k][j]) min dp1[i][j] [i] dp1 i j dp1[i][k] + dp1[k][j] dp1[i][k] [i] dp1 i k dp1[k][j] [k] dp1 k j [MAX_INT]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [MAX_INT]*N [MAX_INT] MAX_INT N dp2 = [[MAX_INT]*N for _ in range(N)] dp2 [[MAX_INT]*N for _ in range(N)] for i in range(N):
  for j in range(N):
    if dp1[i][j] <= L:
      dp2[i][j] = 1 i range(N) range N for j in range(N):
    if dp1[i][j] <= L:
      dp2[i][j] = 1 j range(N) range N if dp1[i][j] <= L:
      dp2[i][j] = 1 dp1[i][j] <= L dp1[i][j] [i] dp1 i j L dp2[i][j] = 1 dp2[i][j] [i] dp2 i j 1 for k in range(N):
  for i in range(N):
    for j in range(N):
      if i == j:
        dp2[i][j] = 0
      else:
        dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]) k range(N) range N for i in range(N):
    for j in range(N):
      if i == j:
        dp2[i][j] = 0
      else:
        dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]) i range(N) range N for j in range(N):
      if i == j:
        dp2[i][j] = 0
      else:
        dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]) j range(N) range N if i == j:
        dp2[i][j] = 0
      else:
        dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]) i == j i j dp2[i][j] = 0 dp2[i][j] [i] dp2 i j 0 dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]) dp2[i][j] [i] dp2 i j min(dp2[i][j], dp2[i][k] + dp2[k][j]) min dp2[i][j] [i] dp2 i j dp2[i][k] + dp2[k][j] dp2[i][k] [i] dp2 i k dp2[k][j] [k] dp2 k j for s, t in q:
  if dp2[s - 1][t - 1] == MAX_INT:
    print(-1)
  else:
    print(dp2[s - 1][t - 1] - 1) s t q if dp2[s - 1][t - 1] == MAX_INT:
    print(-1)
  else:
    print(dp2[s - 1][t - 1] - 1) dp2[s - 1][t - 1] == MAX_INT dp2[s - 1][t - 1] [s - 1] dp2 s - 1 s 1 t - 1 t 1 MAX_INT print(-1) print -1 print(dp2[s - 1][t - 1] - 1) print dp2[s - 1][t - 1] - 1 dp2[s - 1][t - 1] [s - 1] dp2 s - 1 s 1 t - 1 t 1 1 MIN_INT = -MAX_INT -MAX_INT MIN_INT def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I N, M, L = IL() IL() N def S(): return input() def S(): return input() S def SL(): return input().split() def SL(): return input().split() SL Q = I() I() Q MAX_INT = int(10e10) int(10e10) MAX_INT M, L = IL() IL() M abc = [IL() for _ in range(M)] [IL() for _ in range(M)] abc mod = 1000000007 1000000007 mod def IL(): return list(map(int,input().split())) def IL(): return list(map(int,input().split())) IL dp2 = [[MAX_INT]*N for _ in range(N)] [[MAX_INT]*N for _ in range(N)] dp2 L = IL() IL() L q = [IL() for _ in range(Q)] [IL() for _ in range(Q)] q dp1 = [[MAX_INT]*N for _ in range(N)] [[MAX_INT]*N for _ in range(N)] dp1
import math
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N, M, L = IL()
abc = [IL() for _ in range(M)]
Q = I()
q = [IL() for _ in range(Q)]

dp1 = [[MAX_INT]*N for _ in range(N)]
for a, b, c in abc:
  dp1[a - 1][b - 1] = c
  dp1[b - 1][a - 1] = c

for k in range(N):
  for i in range(N):
    for j in range(N):
      if i == j:
        dp1[i][j] = 0
      else:
        dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k][j])

dp2 = [[MAX_INT]*N for _ in range(N)]
for i in range(N):
  for j in range(N):
    if dp1[i][j] <= L:
      dp2[i][j] = 1

for k in range(N):
  for i in range(N):
    for j in range(N):
      if i == j:
        dp2[i][j] = 0
      else:
        dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j])

for s, t in q:
  if dp2[s - 1][t - 1] == MAX_INT:
    print(-1)
  else:
    print(dp2[s - 1][t - 1] - 1)