# -*- coding: utf-8 -*-

#幅優先探索

#TLE

import sys

from collections import deque



N=eval(input())



a=[[] for i in range(N+1)]

#隣接リスト

for i in range(N-1):

	x,y,z=list(map(int,input().split()))

	a[x].append((y,z))

	a[y].append((x,z))



#print a



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





b=[]

for i in range(Q):

	b.append(list(map(int, input().split())))

#print b







#訪問判別フラグ

F=(N+1)*[0]



#Queue

q=deque()



#距離

dist=[0 for i in range(N+1)]





length=0

#幅優先探索

q.append(K)

while len(q)!=0:

	v=q.popleft()

	F[v]=1

	for u,length in a[v]:

		if F[u]==0:

			q.append(u)

			dist[u]=dist[v]+length





#print dist





for x in range(len(b)):

	print(dist[ b[x][0] ]+ dist[ b[x][1] ])





import sys

from collections import deque



N=eval(input())



nl=[ [] for i in range(N+1) ]

for _ in range(N-1):

	a,b,c=list(map(int, sys.stdin.readline().split())) 

	nl[a].append( (b,c) )

	nl[b].append( (a,c) )



Q,K=list(map(int, sys.stdin.readline().split()))



question=[ list(map(int, sys.stdin.readline().split()))  for i in range(Q) ] 



Visit=[ None for i in range(N+1) ] 

Visit[K]=0



q=deque()

q.append(K)





while q:

	fro=q.popleft()

	for to,cost in nl[fro]:

		if Visit[to] is None:

			Visit[to]=Visit[fro]+cost

			q.append(to)





for x, y in question:

	print(Visit[x]+Visit[y])

# -*- coding: utf-8 -*-
# 幅優先探索
# TLE
import sys
from collections import deque

N = eval(input())
a = [[] for i in range(N + 1)]
# 隣接リスト
for i in range(N - 1):
    x, y, z = list(map(int, input().split()))
    a[x].append((y, z))
    a[y].append((x, z))
# print a
Q, K = list(map(int, input().split()))
b = []
for i in range(Q):
    b.append(list(map(int, input().split())))
# print b
# 訪問判別フラグ
F = (N + 1) * [0]
# Queue
q = deque()
# 距離
dist = [0 for i in range(N + 1)]
length = 0
# 幅優先探索
q.append(K)
while len(q) != 0:
    v = q.popleft()
    F[v] = 1
    for u, length in a[v]:
        if F[u] == 0:
            q.append(u)
            dist[u] = dist[v] + length
# print dist
for x in range(len(b)):
    print(dist[b[x][0]] + dist[b[x][1]])

import sys
from collections import deque

N = eval(input())
nl = [[] for i in range(N + 1)]
for _ in range(N - 1):
    a, b, c = list(map(int, sys.stdin.readline().split()))
    nl[a].append((b, c))
    nl[b].append((a, c))
Q, K = list(map(int, sys.stdin.readline().split()))
question = [list(map(int, sys.stdin.readline().split())) for i in range(Q)]
Visit = [None for i in range(N + 1)]
Visit[K] = 0
q = deque()
q.append(K)
while q:
    fro = q.popleft()
    for to, cost in nl[fro]:
        if Visit[to] is None:
            Visit[to] = Visit[fro] + cost
            q.append(to)
for x, y in question:
    print(Visit[x] + Visit[y])

-# -*- coding: utf-8 -*- -# 幅優先探索 -# TLE -a = [[] for i in range(N + 1)] -# 隣接リスト -for i in range(N - 1): -    x, y, z = list(map(int, input().split())) -    a[x].append((y, z)) -    a[y].append((x, z)) -# print a -Q, K = list(map(int, input().split())) -b = [] -for i in range(Q): -    b.append(list(map(int, input().split()))) -# print b -# 訪問判別フラグ -F = (N + 1) * [0] -# Queue +nl = [[] for i in range(N + 1)] +for _ in range(N - 1): +    a, b, c = list(map(int, sys.stdin.readline().split())) +    nl[a].append((b, c)) +    nl[b].append((a, c)) +Q, K = list(map(int, sys.stdin.readline().split())) +question = [list(map(int, sys.stdin.readline().split())) for i in range(Q)] +Visit = [None for i in range(N + 1)] +Visit[K] = 0 -# 距離 -dist = [0 for i in range(N + 1)] -length = 0 -# 幅優先探索 -while len(q) != 0: -    v = q.popleft() -    F[v] = 1 -    for u, length in a[v]: -        if F[u] == 0: -            q.append(u) -            dist[u] = dist[v] + length -# print dist -for x in range(len(b)): -    print(dist[b[x][0]] + dist[b[x][1]]) +while q: +    fro = q.popleft() +    for to, cost in nl[fro]: +        if Visit[to] is None: +            Visit[to] = Visit[fro] + cost +            q.append(to) +for x, y in question: +    print(Visit[x] + Visit[y])