n,m,l = map(int,input().split())
g = [[1<<30]*n for _ in range(n)]
for _ in range(m):
  a,b,c = map(int,input().split())
  g[a-1][b-1] = c
  g[b-1][a-1] = c
for i in range(n):
  g[i][i] = 0

def bell(g,n):
  for k in range(n):
    for i in range(n-1):
      for j in range(i+1,n):
        if g[i][j] > g[i][k] + g[k][j]:
          g[i][j] = g[i][k] + g[k][j]
          g[j][i] = g[i][j]
  return g

g = bell(g,n)
for i in range(n):
  for j in range(n):
    if i == j:
      g[i][j] = 0
    elif g[i][j] <= l:
      g[i][j] = 1
    else:
      g[i][j] = 1<<30
g = bell(g,n)

q = int(input())
for _ in range(q):
  s,t = map(int,input().split())
  if g[s-1][t-1]>>30:
    print(-1)
  else:
    print(g[s-1][t-1]-1) n,m,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l [1<<30]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [1<<30]*n [1<<30] 1<<30 1 30 n g = [[1<<30]*n for _ in range(n)] g [[1<<30]*n for _ in range(n)] for _ in range(m):
  a,b,c = map(int,input().split())
  g[a-1][b-1] = c
  g[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 g[a-1][b-1] = c g[a-1][b-1] [a-1] g a-1 a 1 b-1 b 1 c g[b-1][a-1] = c g[b-1][a-1] [b-1] g b-1 b 1 a-1 a 1 c for i in range(n):
  g[i][i] = 0 i range(n) range n g[i][i] = 0 g[i][i] [i] g i i 0 def bell(g,n):
  for k in range(n):
    for i in range(n-1):
      for j in range(i+1,n):
        if g[i][j] > g[i][k] + g[k][j]:
          g[i][j] = g[i][k] + g[k][j]
          g[j][i] = g[i][j]
  return g bell for k in range(n):
    for i in range(n-1):
      for j in range(i+1,n):
        if g[i][j] > g[i][k] + g[k][j]:
          g[i][j] = g[i][k] + g[k][j]
          g[j][i] = g[i][j]
   k range(n) range n for i in range(n-1):
      for j in range(i+1,n):
        if g[i][j] > g[i][k] + g[k][j]:
          g[i][j] = g[i][k] + g[k][j]
          g[j][i] = g[i][j]
   i range(n-1) range n-1 n 1 for j in range(i+1,n):
        if g[i][j] > g[i][k] + g[k][j]:
          g[i][j] = g[i][k] + g[k][j]
          g[j][i] = g[i][j]
   j range(i+1,n) range i+1 i 1 n if g[i][j] > g[i][k] + g[k][j]:
          g[i][j] = g[i][k] + g[k][j]
          g[j][i] = g[i][j]
   g[i][j] > g[i][k] + g[k][j] g[i][j] [i] g i j g[i][k] + g[k][j] g[i][k] [i] g i k g[k][j] [k] g k j g[i][j] = g[i][k] + g[k][j] g[i][j] [i] g i j g[i][k] + g[k][j] g[i][k] [i] g i k g[k][j] [k] g k j g[j][i] = g[i][j] g[j][i] [j] g j i g[i][j] [i] g i j return g g g g n n g = bell(g,n) g bell(g,n) bell g n for i in range(n):
  for j in range(n):
    if i == j:
      g[i][j] = 0
    elif g[i][j] <= l:
      g[i][j] = 1
    else:
      g[i][j] = 1<<30 i range(n) range n for j in range(n):
    if i == j:
      g[i][j] = 0
    elif g[i][j] <= l:
      g[i][j] = 1
    else:
      g[i][j] = 1<<30 j range(n) range n if i == j:
      g[i][j] = 0
    elif g[i][j] <= l:
      g[i][j] = 1
    else:
      g[i][j] = 1<<30 i == j i j g[i][j] = 0 g[i][j] [i] g i j 0 elif g[i][j] <= l:
      g[i][j] = 1
     g[i][j] <= l g[i][j] [i] g i j l g[i][j] = 1 g[i][j] [i] g i j 1 g[i][j] = 1<<30 g[i][j] [i] g i j 1<<30 1 30 g = bell(g,n) g bell(g,n) bell g n q = int(input()) q int(input()) int input() input for _ in range(q):
  s,t = map(int,input().split())
  if g[s-1][t-1]>>30:
    print(-1)
  else:
    print(g[s-1][t-1]-1) _ range(q) range q s,t = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t if g[s-1][t-1]>>30:
    print(-1)
  else:
    print(g[s-1][t-1]-1) g[s-1][t-1]>>30 g[s-1][t-1] [s-1] g s-1 s 1 t-1 t 1 30 print(-1) print -1 print(g[s-1][t-1]-1) print g[s-1][t-1]-1 g[s-1][t-1] [s-1] g s-1 s 1 t-1 t 1 1 m,l = map(int,input().split()) map(int,input().split()) m b,c = map(int,input().split()) map(int,input().split()) b t = map(int,input().split()) map(int,input().split()) t g = bell(g,n) bell(g,n) g q = int(input()) int(input()) q a,b,c = map(int,input().split()) map(int,input().split()) a g = bell(g,n) bell(g,n) g n,m,l = map(int,input().split()) map(int,input().split()) n l = map(int,input().split()) map(int,input().split()) l def bell(g,n):
  for k in range(n):
    for i in range(n-1):
      for j in range(i+1,n):
        if g[i][j] > g[i][k] + g[k][j]:
          g[i][j] = g[i][k] + g[k][j]
          g[j][i] = g[i][j]
  return g def bell(g,n):
  for k in range(n):
    for i in range(n-1):
      for j in range(i+1,n):
        if g[i][j] > g[i][k] + g[k][j]:
          g[i][j] = g[i][k] + g[k][j]
          g[j][i] = g[i][j]
  return g bell c = map(int,input().split()) map(int,input().split()) c g = [[1<<30]*n for _ in range(n)] [[1<<30]*n for _ in range(n)] g s,t = map(int,input().split()) map(int,input().split()) s
n,m,l = map(int,input().split())
g = [[1<<30]*n for _ in range(n)]
for _ in range(m):
  a,b,c = map(int,input().split())
  g[a-1][b-1] = c
  g[b-1][a-1] = c
for i in range(n):
  g[i][i] = 0

def bell(g,n):
  for k in range(n):
    for i in range(n-1):
      for j in range(i+1,n):
        if g[i][j] > g[i][k] + g[k][j]:
          g[i][j] = g[i][k] + g[k][j]
          g[j][i] = g[i][j]
  return g

g = bell(g,n)
for i in range(n):
  for j in range(n):
    if i == j:
      g[i][j] = 0
    elif g[i][j] <= l:
      g[i][j] = 1
    else:
      g[i][j] = 1<<30
g = bell(g,n)

q = int(input())
for _ in range(q):
  s,t = map(int,input().split())
  if g[s-1][t-1]>>30:
    print(-1)
  else:
    print(g[s-1][t-1]-1)