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 collections import defaultdict
  from heapq import heappop, heappush
  
  
  class Graph(object):
  
      def __init__(self):
          self.graph = defaultdict(list)
  
      def __len__(self):
          return len(self.graph)
  
      def add_edge(self, src, dst, weight=1):
          self.graph[src].append((dst, weight))
  
      def get_nodes(self):
          return self.graph.keys()
  
  
  class Dijkstra(object):
  
      def __init__(self, graph, start, l):
          self.g = graph.graph
  
          # startノードからの最短距離
          # startノードは0, それ以外は無限大で初期化
          self.dist = defaultdict(lambda: float("inf"))
          self.dist[start] = 0
  
          # 最短経路での1つ前のノード
          self.prev = defaultdict(lambda: None)
  
          # startノードをキューに入れる
          self.Q = []
          heappush(self.Q, (self.dist[start], start))
  
          while self.Q:
              # 優先度（距離）が最小であるキューを取り出す
              dist_u, u = heappop(self.Q)
              if self.dist[u] < dist_u:
                  continue
              for v, weight in self.g[u]:
                  alt = dist_u + weight
                  if dist_u != 0:
                      if (dist_u - 1) // l != (alt - 1) // l:
                          alt = ((dist_u - 1) // l + 1) * l + weight
                  if self.dist[v] > alt:
                      self.dist[v] = alt
                      self.prev[v] = u
                      heappush(self.Q, (alt, v))
  
      def shortest_distance(self, goal):
          if self.dist[goal] == float("inf"):
              return -1
          return self.dist[goal] // l
  
      def shortest_path(self, goal):
          path = []
          node = goal
          while node is not None:
              path.append(node)
              node = self.prev[node]
          return path[::-1]
  
  
  n, m, l = map(int, input().split())
  abc = [list(map(int, input().split())) for i in range(m)]
  q = int(input())
  st = [list(map(int, input().split())) for i in range(q)]
  path = Graph()
  for i in abc:
      a, b, c = i[0], i[1], i[2]
      if c <= l:
          path.add_edge(a - 1, b - 1, c)
          path.add_edge(b - 1, a - 1, c)
  for i in st:
      s, t = i[0] - 1, i[1] - 1
      s_path = Dijkstra(path, s, l)
      ans = s_path.shortest_distance(t)
      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"}]