import sys

def main():
  input = sys.stdin.readline
  n, m, l = map(int, input().split())
  
  inf = pow(10, 10)
  towns = [[inf]*n for _ in range(n)]
  
  for _ in range(m):
    a, b, c = map(int, input().split())
    if c > l:
      continue
    towns[a-1][b-1] = c
    towns[b-1][a-1] = c
  
  for k in range(n):
    for i in range(n):
      for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j] and l >= towns[i][k]+towns[k][j]:
          towns[i][j] = towns[i][k]+towns[k][j]
  
  for i in range(n):
    for j in range(n):
      if towns[i][j] == inf:
        continue
      towns[i][j] = 0
  
  for k in range(n):
    for i in range(n):
      for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j]+1:
          towns[i][j] = towns[i][k]+towns[k][j]+1

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

if __name__ == "__main__":
  main() import sys sys def main():
  input = sys.stdin.readline
  n, m, l = map(int, input().split())
  
  inf = pow(10, 10)
  towns = [[inf]*n for _ in range(n)]
  
  for _ in range(m):
    a, b, c = map(int, input().split())
    if c > l:
      continue
    towns[a-1][b-1] = c
    towns[b-1][a-1] = c
  
  for k in range(n):
    for i in range(n):
      for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j] and l >= towns[i][k]+towns[k][j]:
          towns[i][j] = towns[i][k]+towns[k][j]
  
  for i in range(n):
    for j in range(n):
      if towns[i][j] == inf:
        continue
      towns[i][j] = 0
  
  for k in range(n):
    for i in range(n):
      for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j]+1:
          towns[i][j] = towns[i][k]+towns[k][j]+1

  q = int(input())
  for _ in range(q):
    s, t = map(int, input().split())
    print(towns[s-1][t-1] if towns[s-1][t-1] != inf else -1) main 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 inf = pow(10, 10) inf pow(10, 10) pow 10 10 [inf]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [inf]*n [inf] inf n towns = [[inf]*n for _ in range(n)] towns [[inf]*n for _ in range(n)] for _ in range(m):
    a, b, c = map(int, input().split())
    if c > l:
      continue
    towns[a-1][b-1] = c
    towns[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:
      continue
     c > l c l continue towns[a-1][b-1] = c towns[a-1][b-1] [a-1] towns a-1 a 1 b-1 b 1 c towns[b-1][a-1] = c towns[b-1][a-1] [b-1] towns 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 towns[i][j] > towns[i][k]+towns[k][j] and l >= towns[i][k]+towns[k][j]:
          towns[i][j] = towns[i][k]+towns[k][j]
  
   k range(n) range n for i in range(n):
      for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j] and l >= towns[i][k]+towns[k][j]:
          towns[i][j] = towns[i][k]+towns[k][j]
  
   i range(n) range n for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j] and l >= towns[i][k]+towns[k][j]:
          towns[i][j] = towns[i][k]+towns[k][j]
  
   j range(n) range n if towns[i][j] > towns[i][k]+towns[k][j] and l >= towns[i][k]+towns[k][j]:
          towns[i][j] = towns[i][k]+towns[k][j]
  
   towns[i][j] > towns[i][k]+towns[k][j] and l >= towns[i][k]+towns[k][j] towns[i][j] > towns[i][k]+towns[k][j] towns[i][j] [i] towns i j towns[i][k]+towns[k][j] towns[i][k] [i] towns i k towns[k][j] [k] towns k j l >= towns[i][k]+towns[k][j] l towns[i][k]+towns[k][j] towns[i][k] [i] towns i k towns[k][j] [k] towns k j towns[i][j] = towns[i][k]+towns[k][j] towns[i][j] [i] towns i j towns[i][k]+towns[k][j] towns[i][k] [i] towns i k towns[k][j] [k] towns k j for i in range(n):
    for j in range(n):
      if towns[i][j] == inf:
        continue
      towns[i][j] = 0
  
   i range(n) range n for j in range(n):
      if towns[i][j] == inf:
        continue
      towns[i][j] = 0
  
   j range(n) range n if towns[i][j] == inf:
        continue
       towns[i][j] == inf towns[i][j] [i] towns i j inf continue towns[i][j] = 0 towns[i][j] [i] towns i j 0 for k in range(n):
    for i in range(n):
      for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j]+1:
          towns[i][j] = towns[i][k]+towns[k][j]+1

   k range(n) range n for i in range(n):
      for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j]+1:
          towns[i][j] = towns[i][k]+towns[k][j]+1

   i range(n) range n for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j]+1:
          towns[i][j] = towns[i][k]+towns[k][j]+1

   j range(n) range n if towns[i][j] > towns[i][k]+towns[k][j]+1:
          towns[i][j] = towns[i][k]+towns[k][j]+1

   towns[i][j] > towns[i][k]+towns[k][j]+1 towns[i][j] [i] towns i j towns[i][k]+towns[k][j]+1 towns[i][k]+towns[k][j] towns[i][k] [i] towns i k towns[k][j] [k] towns k j 1 towns[i][j] = towns[i][k]+towns[k][j]+1 towns[i][j] [i] towns i j towns[i][k]+towns[k][j]+1 towns[i][k]+towns[k][j] towns[i][k] [i] towns i k towns[k][j] [k] towns k j 1 q = int(input()) q int(input()) int input() input for _ in range(q):
    s, t = map(int, input().split())
    print(towns[s-1][t-1] if towns[s-1][t-1] != inf else -1) _ range(q) range q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t print(towns[s-1][t-1] if towns[s-1][t-1] != inf else -1) print towns[s-1][t-1] if towns[s-1][t-1] != inf else -1 towns[s-1][t-1] != inf towns[s-1][t-1] [s-1] towns s-1 s 1 t-1 t 1 inf towns[s-1][t-1] [s-1] towns s-1 s 1 t-1 t 1 -1 if __name__ == "__main__":
  main() __name__ == "__main__" __name__ "__main__" main() main def main():
  input = sys.stdin.readline
  n, m, l = map(int, input().split())
  
  inf = pow(10, 10)
  towns = [[inf]*n for _ in range(n)]
  
  for _ in range(m):
    a, b, c = map(int, input().split())
    if c > l:
      continue
    towns[a-1][b-1] = c
    towns[b-1][a-1] = c
  
  for k in range(n):
    for i in range(n):
      for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j] and l >= towns[i][k]+towns[k][j]:
          towns[i][j] = towns[i][k]+towns[k][j]
  
  for i in range(n):
    for j in range(n):
      if towns[i][j] == inf:
        continue
      towns[i][j] = 0
  
  for k in range(n):
    for i in range(n):
      for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j]+1:
          towns[i][j] = towns[i][k]+towns[k][j]+1

  q = int(input())
  for _ in range(q):
    s, t = map(int, input().split())
    print(towns[s-1][t-1] if towns[s-1][t-1] != inf else -1) def main():
  input = sys.stdin.readline
  n, m, l = map(int, input().split())
  
  inf = pow(10, 10)
  towns = [[inf]*n for _ in range(n)]
  
  for _ in range(m):
    a, b, c = map(int, input().split())
    if c > l:
      continue
    towns[a-1][b-1] = c
    towns[b-1][a-1] = c
  
  for k in range(n):
    for i in range(n):
      for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j] and l >= towns[i][k]+towns[k][j]:
          towns[i][j] = towns[i][k]+towns[k][j]
  
  for i in range(n):
    for j in range(n):
      if towns[i][j] == inf:
        continue
      towns[i][j] = 0
  
  for k in range(n):
    for i in range(n):
      for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j]+1:
          towns[i][j] = towns[i][k]+towns[k][j]+1

  q = int(input())
  for _ in range(q):
    s, t = map(int, input().split())
    print(towns[s-1][t-1] if towns[s-1][t-1] != inf else -1) main
import sys

def main():
  input = sys.stdin.readline
  n, m, l = map(int, input().split())
  
  inf = pow(10, 10)
  towns = [[inf]*n for _ in range(n)]
  
  for _ in range(m):
    a, b, c = map(int, input().split())
    if c > l:
      continue
    towns[a-1][b-1] = c
    towns[b-1][a-1] = c
  
  for k in range(n):
    for i in range(n):
      for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j] and l >= towns[i][k]+towns[k][j]:
          towns[i][j] = towns[i][k]+towns[k][j]
  
  for i in range(n):
    for j in range(n):
      if towns[i][j] == inf:
        continue
      towns[i][j] = 0
  
  for k in range(n):
    for i in range(n):
      for j in range(n):
        if towns[i][j] > towns[i][k]+towns[k][j]+1:
          towns[i][j] = towns[i][k]+towns[k][j]+1

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

if __name__ == "__main__":
  main()