output_description: Print Q lines.
  
  The i-th line should contain the minimum number of times the tank needs to be
  fulled while traveling from Town s_i to Town t_i. If Town t_i is unreachable,
  the line should contain -1 instead.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M L
      A_1 B_1 C_1
      :
      A_M B_M C_M
      Q
      s_1 t_1
      :
      s_Q t_Q
attempt: from math import isinf
  
  
  class WarshallFloyd(object):
  
      def __init__(self, adj):
          """
          ワーシャル・フロイド法によって全頂点間の最短距離を O(|V|^3) で計算する。
  
          :param adj: 隣接行列 adj[i][j] でi番目の頂点からj番目の頂点へのコストを示す パスがなければINF
          """
          self._dist = adj  # 各頂点間の最短距離 初期値として隣接行列をそのまま用い、[i, i]要素を0に初期化する
          for i in range(len(adj)):
              self._dist[i][i] = 0
  
          self._solve()
  
      def _solve(self):
          v_len = len(self._dist)
          for i in range(v_len):  # 経由する頂点
              for j in range(v_len):  # 開始頂点
                  for k in range(v_len):  # 終端
                      self._dist[j][k] = min(
                          self._dist[j][k], self._dist[j][i] + self._dist[i][k]
                      )
  
      def distance(self, start, goal):
          return self._dist[start][goal]
  
      def path(self, start, goal):
          pass
  
  
  N, M, L = map(int, input().split())
  adj = [[float("inf") for _ in range(N)] for _ in range(N)]
  for A, B, C in [tuple(map(int, input().split())) for _ in range(M)]:
      adj[A - 1][B - 1] = C
      adj[B - 1][A - 1] = C
  
  wf = WarshallFloyd(adj)
  
  adj2 = [[float("inf") for _ in range(N)] for _ in range(N)]
  for i in range(N):
      for j in range(N):
          if i == j:
              continue
          if wf.distance(i, j) <= L:
              adj2[i][j] = 1
  wf2 = WarshallFloyd(adj2)
  
  Q = int(input())
  for s, t in [tuple(map(int, input().split())) for _ in range(Q)]:
      ans = wf2.distance(s - 1, t - 1) - 1
      if isinf(ans):
          print(-1)
      else:
          print(ans)
  
problem_description: Statement
  
  There are N towns numbered 1 to N and M roads. The i-th road connects Town A_i
  and Town B_i bidirectionally and has a length of C_i.
  
  Takahashi will travel between these towns by car, passing through these roads.
  The fuel tank of his car can contain at most L liters of fuel, and one liter
  of fuel is consumed for each unit distance traveled. When visiting a town
  while traveling, he can full the tank (or choose not to do so). Travel that
  results in the tank becoming empty halfway on the road cannot be done.
  
  Process the following Q queries:
  
    * The tank is now full. Find the minimum number of times he needs to full his tank while traveling from Town s_i to Town t_i. If Town t_i is unreachable, print -1.
samples: [{"input": "3 2 5\n    1 2 3\n    2 3 3\n    2\n    3 2\n    1 3", "output": "0\n    1\n    \n\nTo travel from Town 3 to Town 2, we can use the second road to reach Town 2\nwithout fueling the tank on the way.\n\nTo travel from Town 1 to Town 3, we can first use the first road to get to\nTown 2, full the tank, and use the second road to reach Town 3.\n\n* * *"}, {"input": "4 0 1\n    1\n    2 1", "output": "-1\n    \n\nThere may be no road at all.\n\n* * *"}, {"input": "5 4 4\n    1 2 2\n    2 3 2\n    3 4 3\n    4 5 2\n    20\n    2 1\n    3 1\n    4 1\n    5 1\n    1 2\n    3 2\n    4 2\n    5 2\n    1 3\n    2 3\n    4 3\n    5 3\n    1 4\n    2 4\n    3 4\n    5 4\n    1 5\n    2 5\n    3 5\n    4 5", "output": "0\n    0\n    1\n    2\n    0\n    0\n    1\n    2\n    0\n    0\n    0\n    1\n    1\n    1\n    0\n    0\n    2\n    2\n    1\n    0"}]