output_description: Print the responses to the queries in Q lines.  
  In the j-th line j(1≤j≤Q), print the response to the j-th query.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N  
      a_1 b_1 c_1  
      :  
      a_{N-1} b_{N-1} c_{N-1}
      Q K
      x_1 y_1
      :  
      x_{Q} y_{Q}
attempt: from heapq import heappop, heappush
  
  icase = 0
  if icase == 0:
      n = int(input())
      g = [[] for i in range(n)]
      for i in range(n - 1):
          ai, bi, ci = map(int, input().split())
          g[ai - 1].append((bi - 1, ci))
          g[bi - 1].append((ai - 1, ci))
  if icase == 1:
      n = 5
      g = [[(1, 1), (2, 1)], [(0, 1), (3, 1)], [(0, 1), (4, 1)], [(1, 1)], [(2, 1)]]
  if icase == 2:
      n = 7
      g = [
          [(1, 1), (2, 3), (3, 5), (4, 7), (5, 9), (6, 11)],
          [(0, 1)],
          [(0, 3)],
          [(0, 5)],
          [(0, 7)],
          [(0, 9)],
          [(0, 11)],
      ]
  
  q, k = map(int, input().split())
  k = k - 1
  
  hq = []
  heappush(hq, (0, k))
  
  inf = float("INF")
  dist = [inf] * n
  dist[k] = 0
  while len(hq) > 0:
      dd, state = heappop(hq)
      #    print("dd:",dd,"state:",state,"q:",q)
      for v, dv in g[state]:
          #        print("v:",v,"dv:",dv,"g[state]:",g[state],"parent[v]:",parent[v])
          if dist[v] > dist[state] + dv:
              dist[v] = dist[state] + dv
              heappush(hq, (dist[v], v))
  #            print(" state:",state,"v:",v,"dist[v]",dist[v])
  
  for i in range(q):
      xi, yi = map(int, input().split())
      print(dist[xi - 1] + dist[yi - 1])
  
problem_description: Statement
  
  You are given a tree with N vertices.  
  Here, a _tree_ is a kind of graph, and more specifically, a connected
  undirected graph with N-1 edges, where N is the number of its vertices.  
  The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of
  c_i.
  
  You are also given Q queries and an integer K. In the j-th query (1≤j≤Q):
  
    * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
samples: [{"input": "5\n    1 2 1\n    1 3 1\n    2 4 1\n    3 5 1\n    3 1\n    2 4\n    2 3\n    4 5", "output": "3\n    2\n    4\n    \n\nThe shortest paths for the three queries are as follows:\n\n  * Query 1: Vertex 2 \u2192 Vertex 1 \u2192 Vertex 2 \u2192 Vertex 4 : Length 1+1+1=3\n  * Query 2: Vertex 2 \u2192 Vertex 1 \u2192 Vertex 3 : Length 1+1=2\n  * Query 3: Vertex 4 \u2192 Vertex 2 \u2192 Vertex 1 \u2192 Vertex 3 \u2192 Vertex 5 : Length 1+1+1+1=4\n\n* * *"}, {"input": "7\n    1 2 1\n    1 3 3\n    1 4 5\n    1 5 7\n    1 6 9\n    1 7 11\n    3 2\n    1 3\n    4 5\n    6 7", "output": "5\n    14\n    22\n    \n\nThe path for each query must pass Vertex K=2.\n\n* * *"}, {"input": "10\n    1 2 1000000000\n    2 3 1000000000\n    3 4 1000000000\n    4 5 1000000000\n    5 6 1000000000\n    6 7 1000000000\n    7 8 1000000000\n    8 9 1000000000\n    9 10 1000000000\n    1 1\n    9 10", "output": "17000000000"}]