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: import sys
  from heapq import heappush, heappop, heappushpop, heapify, heapreplace
  from itertools import permutations
  from bisect import bisect_left, bisect_right
  from collections import Counter, deque
  from fractions import gcd
  from math import factorial, sqrt
  INF = 1 << 60
  sys.setrecursionlimit(10 ** 6)
  
  class UnionFind():
      def __init__(self, n):
          self.n = n
          self.parents = [-1] * n
  
      def find(self, x):
          if self.parents[x] < 0:
              return x
          else:
              self.parents[x] = self.find(self.parents[x])
              return self.parents[x]
  
      def union(self, x, y):
          x = self.find(x)
          y = self.find(y)
  
          if x == y:
              return
  
          if self.parents[x] > self.parents[y]:
              x, y = y, x
  
          self.parents[x] += self.parents[y]
          self.parents[y] = x
  
      def size(self, x):
          return -self.parents[self.find(x)]
  
      def same(self, x, y):
          return self.find(x) == self.find(y)
  
      def members(self, x):
          root = self.find(x)
          return [i for i in range(self.n) if self.find(i) == root]
  
      def roots(self):
          return [i for i, x in enumerate(self.parents) if x < 0]
  
      def group_count(self):
          return len(self.roots())
  
      def all_group_members(self):
          return {r: self.members(r) for r in self.roots()}
  
      def __str__(self):
          return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
  
  def dijkstra(s,n,w,cost):
      #始点sから各頂点への最短距離
      #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
      d = [float("inf")] * n
      used = [False] * n
      d[s] = 0
      
      while True:
          v = -1
          #まだ使われてない頂点の中から最小の距離のものを探す
          for i in range(n):
              if (not used[i]) and (v == -1):
              v = i
              elif (not used[i]) and d[i] < d[v]:
                  v = i
          if v == -1:
              break
          used[v] = True
              
          for j in range(n):
              d[j] = min(d[j],d[v]+cost[v][j])
      return d
  
  
  def factorization(n):
      arr = []
      temp = n
      for i in range(2, int(-(-n**0.5//1))+1):
          if temp%i==0:
              cnt=0
              while temp%i==0:
                  cnt+=1
                  temp //= i
              arr.append([i, cnt])
  
      if temp!=1:
          arr.append([temp, 1])
  
      if arr==[]:
          arr.append([n, 1])
  
      return arr
  
  #ここから書き始める
  n = int(input())
  cost = [[INF for i in range(n)] for i in range(n)] 
  for i in range(n - 1):
      a, b, c = map(int, input().split())
      cost[a - 1][b - 1] = c
      cost[b - 1][a - 1] = c
  q, k = map(int, input().split())   
  ans = [0] * q
  to_k = [0] * n
  to_y = [0] * n
  for i in range(n):
      to_k[i] = dijkstra(i, n, n - 1, cost)[k - 1]
      to_y[i] = dijkstra(k - 1, n, n - 1, cost)[i]
  for i in range(q):
      x, y = map(int, input().split())
      ans[i] = to_k[x - 1] + to_y[y - 1]
  for i in ans:
      print(i)
      
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"}]