from sys import stdin

input = stdin.readline

def BFS(K,path,N):

  """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す"""

  import queue

  dist=[-1]*N

  dist[K]=0

  que=queue.Queue()

  que.put(K)

  while que.qsize():

    label=que.get()

    for i,c in path[label]:

      if dist[i]==-1:

        dist[i]=dist[label]+c

        que.put(i)

  return dist

 

N=int(eval(input()))

path=[ [] for i in range(N)]

for i in range(N-1):

  a,b,c=list(map(int,input().split()))

  path[a-1]+=[(b-1,c)]

  path[b-1]+=[(a-1,c)]

Q,K=list(map(int,input().split()))

xy=[list(map(int,input().split())) for i in range(Q)]

distance=BFS(K-1,path,N)

for i in range(Q):

  print((distance[xy[i][0]-1]+distance[xy[i][1]-1]))
from sys import stdin

input = stdin.readline

def BFS(K,path,N):

  """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す"""

  from collections import deque

  dist=[-1]*N

  dist[K]=0

  que=[]

  que.append(K)

  while que:

    label=que.pop(-1)

    for i,c in path[label]:

      if dist[i]==-1:

        dist[i]=dist[label]+c

        que+=[i]

  return dist

 

N=int(eval(input()))

path=[ [] for i in range(N)]

for i in range(N-1):

  a,b,c=list(map(int,input().split()))

  path[a-1]+=[(b-1,c)]

  path[b-1]+=[(a-1,c)]

Q,K=list(map(int,input().split()))

xy=[list(map(int,input().split())) for i in range(Q)]

distance=BFS(K-1,path,N)

for i in range(Q):

  print((distance[xy[i][0]-1]+distance[xy[i][1]-1]))
from sys import stdin

input = stdin.readline


def BFS(K, path, N):
    """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す"""
    import queue

    dist = [-1] * N
    dist[K] = 0
    que = queue.Queue()
    que.put(K)
    while que.qsize():
        label = que.get()
        for i, c in path[label]:
            if dist[i] == -1:
                dist[i] = dist[label] + c
                que.put(i)
    return dist


N = int(eval(input()))
path = [[] for i in range(N)]
for i in range(N - 1):
    a, b, c = list(map(int, input().split()))
    path[a - 1] += [(b - 1, c)]
    path[b - 1] += [(a - 1, c)]
Q, K = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(Q)]
distance = BFS(K - 1, path, N)
for i in range(Q):
    print((distance[xy[i][0] - 1] + distance[xy[i][1] - 1]))

from sys import stdin

input = stdin.readline


def BFS(K, path, N):
    """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す"""
    from collections import deque

    dist = [-1] * N
    dist[K] = 0
    que = []
    que.append(K)
    while que:
        label = que.pop(-1)
        for i, c in path[label]:
            if dist[i] == -1:
                dist[i] = dist[label] + c
                que += [i]
    return dist


N = int(eval(input()))
path = [[] for i in range(N)]
for i in range(N - 1):
    a, b, c = list(map(int, input().split()))
    path[a - 1] += [(b - 1, c)]
    path[b - 1] += [(a - 1, c)]
Q, K = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(Q)]
distance = BFS(K - 1, path, N)
for i in range(Q):
    print((distance[xy[i][0] - 1] + distance[xy[i][1] - 1]))

-    import queue +    from collections import deque -    que = queue.Queue() -    que.put(K) -    while que.qsize(): -        label = que.get() +    que = [] +    que.append(K) +    while que: +        label = que.pop(-1) -                que.put(i) +                que += [i]