input: from typing import List
  
  def travel_min_cost(n: int, edges: List[List[int]], queries: List[List[int]]) -> List[int]:
      """
      In a given undirected weighted graph with n nodes numbered from 0 to n - 1.
  
      You are provided the integer n and a list of edges, where edges[i] = [u_i, v_i, w_i] signifies an edge between nodes u_i and v_i with a weight of w_i.
  
      A walk through the graph is represented as a series of nodes and edges. The walk initiates and culminates at a node, passing through each edge that connects the consecutive nodes. Note that a walk can traverse the same node or edge multiple times.
  
      The cost of a walk beginning at node u and ending at node v is defined as the bitwise AND of the weights of the edges encountered during the walk. That is, given the sequence of edge weights w_0, w_1, w_2, ..., w_k during the walk, the cost is w_0 & w_1 & w_2 & ... & w_k, where & is the bitwise AND operator.
  
      You are also provided with a 2D list queries, where queries[i] = [s_i, t_i]. For each query, determine the minimum cost of the walk from node s_i to node t_i. If no such walk exists, return -1.
  
      Return a list results, where results[i] represents the minimum cost of a walk for the i-th query.
  
      Examples:
      >>> n = 5, edges = [[0,1,7],[1,3,7],[1,2,1]], queries = [[0,3],[3,4]]
      [1, -1]
      >>> n = 3, edges = [[0,2,7],[0,1,15],[1,2,6],[1,2,1]], queries = [[1,2]]
      [0]
  
      Constraints:
      2 <= n <= 100000
      0 <= edges.length <= 100000
      edges[i].length == 3
      0 <= u_i, v_i <= n - 1
      u_i != v_i
      0 <= w_i <= 100000
      1 <= queries.length <= 100000
      queries[i].length == 2
      0 <= s_i, t_i <= n - 1
      s_i != t_i
      """
output:     import heapq
      from collections import defaultdict
  
      def dijkstra(start):
          heap = [(float('inf'), start)]
          min_costs = {i: float('inf') for i in range(n)}
          min_costs[start] = 0
          while heap:
              curr_cost, u = heapq.heappop(heap)
              if curr_cost != min_costs[u]:
                  continue
              for v, weight in graph[u]:
                  cost = curr_cost & weight
                  if cost < min_costs[v]:
                      min_costs[v] = cost
                      heapq.heappush(heap, (cost, v))
          return min_costs
  
      graph = defaultdict(list)
      for u, v, w in edges:
          graph[u].append((v, w))
          graph[v].append((u, w))
      
      results = []
      for s, t in queries:
          min_costs = dijkstra(s)
          result = min_costs[t]
          if result == float('inf'):
              results.append(-1)
          else:
              results.append(result)
      
      return results