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: N = int(input())
  abc = [[int(n) for n in input().split()] for i in range(N - 1)]
  a, b, c = list(zip(*abc))
  Q, K = map(int, input().split())
  xy = [[int(l) for l in input().split()] for m in range(Q)]
  x, y = list(zip(*xy))
  
  l_rin = [[] for o in range(N)]
  for m in range(N - 1):
      l_rin[a[m] - 1].extend([b[m]])
      l_rin[b[m] - 1].extend([a[m]])
  
  
  def search(top, bottom):
      keiro = [[top]]
      while len(keiro) > 0:
          path = keiro.pop(0)
          r = path[len(path) - 1]
          if r == bottom:
              return path
          else:
              for p in l_rin[r - 1]:
                  if p not in path:
                      new_path = path[:]
                      new_path.append(p)
                      keiro.append(new_path)
  
  
  def distance(fst, scd):
      dist = 0
      ppath = search(fst, scd)
      for pv in range(len(ppath) - 1):
          ppath_set = set(ppath[pv : pv + 2])
          for pn in range(N - 1):
              ab_set = set([a[pn], b[pn]])
              if ab_set == ppath_set:
                  dist = dist + c[pn]
                  exit()
      return dist
  
  
  for s in range(Q):
      print(distance(x[s], K) + distance(K, y[s]))
  
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"}]