n, m, l = map(int, input().split())
x = [[] for _ in range(n)]
dp = [[n*10**9 for _ in range(n)] for _ in range(n)]
for _ in range(m):
  a, b, c = map(int, input().split())
  if c <= l:
    x[a-1].append(b-1)
    x[b-1].append(a-1)
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c
q = int(input())
st = []
for _ in range(q):
  st.append(list(map(int, input().split())))
dp[0][0] = 0
for i in range(1,n):
  dp[i][i] = 0
  for j in range(i):
    for a in x[i]:
      dp[i][j] = min(dp[i][j],dp[i][a]+dp[a][j])
    dp[j][i] = dp[i][j]
  for j in range(i):
    for k in range(i):
      dp[j][k] = min(dp[j][k],dp[j][i]+dp[i][k])
dp2 = [[n for _ in range(n)] for _ in range(n)]
for i in range(n):
  for j in range(n):
    if dp[i][j] <= l:
      dp2[i][j] = 1
for i in range(1,n):
  for j in range(i):
    for k in range(i):
      dp2[i][j] = min(dp2[i][j],dp2[i][k]+dp2[k][j])
    dp2[j][i] = dp2[i][j]
  for j in range(i):
    for k in range(i):
      dp2[j][k] = min(dp2[j][k],dp2[j][i]+dp2[i][k])
for u in st:
  ans = dp2[u[0]-1][u[1]-1]
  if ans >= n:
    print(-1)
  else:
    print(ans-1) n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l [] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [] x = [[] for _ in range(n)] x [[] for _ in range(n)] [n*10**9 for _ in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [n*10**9 for _ in range(n)] dp = [[n*10**9 for _ in range(n)] for _ in range(n)] dp [[n*10**9 for _ in range(n)] for _ in range(n)] for _ in range(m):
  a, b, c = map(int, input().split())
  if c <= l:
    x[a-1].append(b-1)
    x[b-1].append(a-1)
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c _ 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 if c <= l:
    x[a-1].append(b-1)
    x[b-1].append(a-1)
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c c <= l c l x[a-1].append(b-1) [a-1].append [a-1] x a-1 a 1 append b-1 b 1 x[b-1].append(a-1) [b-1].append [b-1] x b-1 b 1 append a-1 a 1 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 q = int(input()) q int(input()) int input() input st = [] st [] for _ in range(q):
  st.append(list(map(int, input().split()))) _ range(q) range q st.append(list(map(int, input().split()))) st.append st append list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split dp[0][0] = 0 dp[0][0] [0] dp 0 0 0 for i in range(1,n):
  dp[i][i] = 0
  for j in range(i):
    for a in x[i]:
      dp[i][j] = min(dp[i][j],dp[i][a]+dp[a][j])
    dp[j][i] = dp[i][j]
  for j in range(i):
    for k in range(i):
      dp[j][k] = min(dp[j][k],dp[j][i]+dp[i][k]) i range(1,n) range 1 n dp[i][i] = 0 dp[i][i] [i] dp i i 0 for j in range(i):
    for a in x[i]:
      dp[i][j] = min(dp[i][j],dp[i][a]+dp[a][j])
    dp[j][i] = dp[i][j]
   j range(i) range i for a in x[i]:
      dp[i][j] = min(dp[i][j],dp[i][a]+dp[a][j])
     a x[i] x i dp[i][j] = min(dp[i][j],dp[i][a]+dp[a][j]) dp[i][j] [i] dp i j min(dp[i][j],dp[i][a]+dp[a][j]) min dp[i][j] [i] dp i j dp[i][a]+dp[a][j] dp[i][a] [i] dp i a dp[a][j] [a] dp a j dp[j][i] = dp[i][j] dp[j][i] [j] dp j i dp[i][j] [i] dp i j for j in range(i):
    for k in range(i):
      dp[j][k] = min(dp[j][k],dp[j][i]+dp[i][k]) j range(i) range i for k in range(i):
      dp[j][k] = min(dp[j][k],dp[j][i]+dp[i][k]) k range(i) range i dp[j][k] = min(dp[j][k],dp[j][i]+dp[i][k]) dp[j][k] [j] dp j k min(dp[j][k],dp[j][i]+dp[i][k]) min dp[j][k] [j] dp j k dp[j][i]+dp[i][k] dp[j][i] [j] dp j i dp[i][k] [i] dp i k [n for _ in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [n for _ in range(n)] dp2 = [[n for _ in range(n)] for _ in range(n)] dp2 [[n for _ in range(n)] for _ in range(n)] for i in range(n):
  for j in range(n):
    if dp[i][j] <= l:
      dp2[i][j] = 1 i range(n) range n for j in range(n):
    if dp[i][j] <= l:
      dp2[i][j] = 1 j range(n) range n if dp[i][j] <= l:
      dp2[i][j] = 1 dp[i][j] <= l dp[i][j] [i] dp i j l dp2[i][j] = 1 dp2[i][j] [i] dp2 i j 1 for i in range(1,n):
  for j in range(i):
    for k in range(i):
      dp2[i][j] = min(dp2[i][j],dp2[i][k]+dp2[k][j])
    dp2[j][i] = dp2[i][j]
  for j in range(i):
    for k in range(i):
      dp2[j][k] = min(dp2[j][k],dp2[j][i]+dp2[i][k]) i range(1,n) range 1 n for j in range(i):
    for k in range(i):
      dp2[i][j] = min(dp2[i][j],dp2[i][k]+dp2[k][j])
    dp2[j][i] = dp2[i][j]
   j range(i) range i for k in range(i):
      dp2[i][j] = min(dp2[i][j],dp2[i][k]+dp2[k][j])
     k range(i) range i 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 dp2[j][i] = dp2[i][j] dp2[j][i] [j] dp2 j i dp2[i][j] [i] dp2 i j for j in range(i):
    for k in range(i):
      dp2[j][k] = min(dp2[j][k],dp2[j][i]+dp2[i][k]) j range(i) range i for k in range(i):
      dp2[j][k] = min(dp2[j][k],dp2[j][i]+dp2[i][k]) k range(i) range i dp2[j][k] = min(dp2[j][k],dp2[j][i]+dp2[i][k]) dp2[j][k] [j] dp2 j k min(dp2[j][k],dp2[j][i]+dp2[i][k]) min dp2[j][k] [j] dp2 j k dp2[j][i]+dp2[i][k] dp2[j][i] [j] dp2 j i dp2[i][k] [i] dp2 i k for u in st:
  ans = dp2[u[0]-1][u[1]-1]
  if ans >= n:
    print(-1)
  else:
    print(ans-1) u st ans = dp2[u[0]-1][u[1]-1] ans dp2[u[0]-1][u[1]-1] [u[0]-1] dp2 u[0]-1 u[0] u 0 1 u[1]-1 u[1] u 1 1 if ans >= n:
    print(-1)
  else:
    print(ans-1) ans >= n ans n print(-1) print -1 print(ans-1) print ans-1 ans 1 n, m, l = map(int, input().split()) map(int, input().split()) n x = [[] for _ in range(n)] [[] for _ in range(n)] x a, b, c = map(int, input().split()) map(int, input().split()) a q = int(input()) int(input()) q dp2 = [[n for _ in range(n)] for _ in range(n)] [[n for _ in range(n)] for _ in range(n)] dp2 st = [] [] st c = map(int, input().split()) map(int, input().split()) c l = map(int, input().split()) map(int, input().split()) l dp = [[n*10**9 for _ in range(n)] for _ in range(n)] [[n*10**9 for _ in range(n)] for _ in range(n)] dp m, l = map(int, input().split()) map(int, input().split()) m b, c = map(int, input().split()) map(int, input().split()) b ans = dp2[u[0]-1][u[1]-1] dp2[u[0]-1][u[1]-1] ans
n, m, l = map(int, input().split())
x = [[] for _ in range(n)]
dp = [[n*10**9 for _ in range(n)] for _ in range(n)]
for _ in range(m):
  a, b, c = map(int, input().split())
  if c <= l:
    x[a-1].append(b-1)
    x[b-1].append(a-1)
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c
q = int(input())
st = []
for _ in range(q):
  st.append(list(map(int, input().split())))
dp[0][0] = 0
for i in range(1,n):
  dp[i][i] = 0
  for j in range(i):
    for a in x[i]:
      dp[i][j] = min(dp[i][j],dp[i][a]+dp[a][j])
    dp[j][i] = dp[i][j]
  for j in range(i):
    for k in range(i):
      dp[j][k] = min(dp[j][k],dp[j][i]+dp[i][k])
dp2 = [[n for _ in range(n)] for _ in range(n)]
for i in range(n):
  for j in range(n):
    if dp[i][j] <= l:
      dp2[i][j] = 1
for i in range(1,n):
  for j in range(i):
    for k in range(i):
      dp2[i][j] = min(dp2[i][j],dp2[i][k]+dp2[k][j])
    dp2[j][i] = dp2[i][j]
  for j in range(i):
    for k in range(i):
      dp2[j][k] = min(dp2[j][k],dp2[j][i]+dp2[i][k])
for u in st:
  ans = dp2[u[0]-1][u[1]-1]
  if ans >= n:
    print(-1)
  else:
    print(ans-1)