input: from typing import List
  
  def find_min_walk_cost(n: int, edges: List[List[int]], queries: List[List[int]]) -> List[int]:
      """
      Consider an undirected graph with n nodes numbered from 0 to n - 1, and each edge has a specific weight.
  
      Given an integer n and a list named edges, where each element edges[i] = [u_i, v_i, w_i] represents an edge between nodes u_i and v_i with weight w_i.
  
      A walk in the graph is defined as a sequence of nodes and edges. A walk starts and ends on nodes, and every edge connects the node preceding it with the node following it. Note that a walk can revisit the same node or edge multiple times.
  
      The cost of a walk from node u to node v is defined as the bitwise AND of the weights of the edges traversed in the walk. For example, if the sequence of edge weights encountered during the walk is w_0, w_1, w_2, ..., w_k, then the cost is computed as w_0 & w_1 & w_2 & ... & w_k, where & is the bitwise AND operator.
  
      Additionally, you are given a list queries, where queries[i] = [s_i, t_i]. For each query, you need to determine the minimum cost of the walk starting at node s_i and ending at node t_i. If such a walk does not exist, return -1.
  
      Return a list of integers where each element in the list corresponds to the minimum cost of the walk for the respective query.
  
      Examples:
      >>> n = 5, edges = [[0,1,7],[1,3,7],[1,2,1]], query = [[0,3],[3,4]]
      [1, -1]
      >>> n = 3, edges = [[0,2,7],[0,1,15],[1,2,6],[1,2,1]], query = [[1,2]]
      [0]
  
      Constraints:
      2 <= n <= 100000
      0 <= len(edges) <= 100000
      edges[i].length == 3
      0 <= u_i, v_i <= n - 1
      u_i != v_i
      0 <= w_i <= 100000
      1 <= len(queries) <= 100000
      queries[i].length == 2
      0 <= s_i, t_i <= n - 1
      s_i != t_i
      """
output:     from collections import defaultdict, deque
      
      def bfs(source, target):
          queue = deque([(source, float('inf'))])
          visited = {source}
          
          while queue:
              current, current_cost = queue.popleft()
              
              if current == target:
                  return current_cost
              
              for neighbor, weight in graph[current]:
                  new_cost = current_cost & weight
                  if neighbor not in visited:
                      visited.add(neighbor)
                      queue.append((neighbor, new_cost))
                      
          return -1
      
      graph = defaultdict(list)
      
      for u, v, w in edges:
          graph[u].append((v, w))
          graph[v].append((u, w))
      
      result = []
      
      for s, t in queries:
          result.append(bfs(s, t))
      
      return result