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: # http://wakabame.hatenablog.com/entry/2017/09/03/213522
  # おまじない
  import sys
  input = sys.stdin.readline
  
  # ノード数
  N = int(input())
  
  # 各要素は(元ノード, 先ノード, コスト)のタプルになっている
  edges = [list(map(int, input().split())) for i in range(N)]
  
  # クエリ数と経由ノード
  Q, K = map(int, input().split())
  
  # クエリ一覧
  xy = [list(map(int, input().split())) for i in range(Q)]
  
  
  # まず経由地から各ノードのへの距離をメモする
  def BFS(K, edges, N):
      # ノード分のリストを持ったリストの定義
      # ノード番号はインデックス-1に対応．つながっている先のノードとそこへのコストのタプルが入る
      roots = [ [] for i in range(N) ]
      for a, b, c in edges:
          roots[a-1] += [(b-1, c)]
          roots[b-1] += [(a-1, c)]
      # memo
      dist = [-1] * N
      # たどり着いたノードのリスト
      stack = []
      stack.append(K)
      dist[K] = 0
      while stack:
          label = stack.pop(-1)
          for i, c roots[label]:
              # 初到達ならmemoしてstackに追加
              # これはグラフが木構造であるから言えること．そうでなければコスト最小値しか採用しては行けない？
              if dist[i] == -1:
                  dist[i] = dist[label] + c
                  stack += [i]
      return dist
  
  distance = BFS(K - 1, edges, N)
  
  for i in range(Q):
      print(distance[xy[i][0] - 1] + distance[xy[i][1] - 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"}]