N =int(eval(input()))

#graph作成

graph = [[] for _ in range(N)]

for _ in range(N-1):

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

    graph[a-1].append((b-1,c))

    graph[b-1].append((a-1,c))



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

K -= 1

query = [tuple(int(x) for x in input().split()) for _ in range(Q)]



        

seen = {K} 

v = [K]

distfromK =[0] * N

while len(v) != 0:  #bfsでdistfromKを埋めていく

    for nv in graph[v[0]]:

        if nv[0] in seen:

            continue

        distfromK[nv[0]] = distfromK[v[0]] + nv[1]

        v.append(nv[0])

        seen.add(nv[0])

    v.pop(0)



for q in query:

    print((distfromK[q[0]-1]+distfromK[q[1]-1]))







from collections import namedtuple, deque

N = int(eval(input()))



connection = [[] for _ in range(N)]

branch = namedtuple('branch',['id', 'dist'])

for _ in range(N-1):

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

    connection[a-1].append(branch(b-1, c))

    connection[b-1].append(branch(a-1, c))



dist = [0] * N #dist from root(K)

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

#bfs

reserved = deque([K-1])

seen = {K-1}

while len(reserved) > 0:

    current = reserved.popleft()

    for next in connection[current]:

        if next.id in seen:

            continue

        seen.add(next.id)

        reserved.append(next.id)

        dist[next.id] = dist[current] + next.dist



#deal with query

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

for x,y in Query:

    print((dist[x-1] + dist[y-1]))





N = int(eval(input()))
# graph作成
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    graph[a - 1].append((b - 1, c))
    graph[b - 1].append((a - 1, c))
Q, K = list(map(int, input().split()))
K -= 1
query = [tuple(int(x) for x in input().split()) for _ in range(Q)]
seen = {K}
v = [K]
distfromK = [0] * N
while len(v) != 0:  # bfsでdistfromKを埋めていく
    for nv in graph[v[0]]:
        if nv[0] in seen:
            continue
        distfromK[nv[0]] = distfromK[v[0]] + nv[1]
        v.append(nv[0])
        seen.add(nv[0])
    v.pop(0)
for q in query:
    print((distfromK[q[0] - 1] + distfromK[q[1] - 1]))

from collections import namedtuple, deque

N = int(eval(input()))
connection = [[] for _ in range(N)]
branch = namedtuple("branch", ["id", "dist"])
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    connection[a - 1].append(branch(b - 1, c))
    connection[b - 1].append(branch(a - 1, c))
dist = [0] * N  # dist from root(K)
Q, K = list(map(int, input().split()))
# bfs
reserved = deque([K - 1])
seen = {K - 1}
while len(reserved) > 0:
    current = reserved.popleft()
    for next in connection[current]:
        if next.id in seen:
            continue
        seen.add(next.id)
        reserved.append(next.id)
        dist[next.id] = dist[current] + next.dist
# deal with query
Query = [list(map(int, input().split())) for _ in range(Q)]
for x, y in Query:
    print((dist[x - 1] + dist[y - 1]))

+from collections import namedtuple, deque + -# graph作成 -graph = [[] for _ in range(N)] +connection = [[] for _ in range(N)] +branch = namedtuple("branch", ["id", "dist"]) -    graph[a - 1].append((b - 1, c)) -    graph[b - 1].append((a - 1, c)) +    connection[a - 1].append(branch(b - 1, c)) +    connection[b - 1].append(branch(a - 1, c)) +dist = [0] * N  # dist from root(K) -K -= 1 -query = [tuple(int(x) for x in input().split()) for _ in range(Q)] -seen = {K} -v = [K] -distfromK = [0] * N -while len(v) != 0:  # bfsでdistfromKを埋めていく -    for nv in graph[v[0]]: -        if nv[0] in seen: +# bfs +reserved = deque([K - 1]) +seen = {K - 1} +while len(reserved) > 0: +    current = reserved.popleft() +    for next in connection[current]: +        if next.id in seen: -        distfromK[nv[0]] = distfromK[v[0]] + nv[1] -        v.append(nv[0]) -        seen.add(nv[0]) -    v.pop(0) -for q in query: -    print((distfromK[q[0] - 1] + distfromK[q[1] - 1])) +        seen.add(next.id) +        reserved.append(next.id) +        dist[next.id] = dist[current] + next.dist +# deal with query +Query = [list(map(int, input().split())) for _ in range(Q)] +for x, y in Query: +    print((dist[x - 1] + dist[y - 1]))