import collections

N = int(eval(input()))

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

ans = [-1]*N

for i in range(N-1):

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

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

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

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

queue = collections.deque([K-1])

ans[K-1] = 0

while queue:

    edge = queue.pop()

    for node in List[edge]:

        index, cost = node

        if ans[index]>0:

            continue

        ans[index] = ans[edge]+cost

        queue.append(index)

for i in range(Q):

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

    print((ans[x-1]+ans[y-1]))
import sys

input = sys.stdin.readline

N = int(eval(input()))

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

ans = [-1]*N

for i in range(N-1):

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

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

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

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

queue = [K-1]

ans[K-1] = 0

while queue:

    edge = queue.pop()

    for node in List[edge]:

        index, cost = node

        if ans[index]>0:

            continue

        ans[index] = ans[edge]+cost

        queue.append(index)

for i in range(Q):

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

    print((ans[x-1]+ans[y-1]))
import collections

N = int(eval(input()))
List = [[] for _ in range(N)]
ans = [-1] * N
for i in range(N - 1):
    a, b, c = list(map(int, input().split()))
    List[a - 1].append((b - 1, c))
    List[b - 1].append((a - 1, c))
Q, K = list(map(int, input().split()))
queue = collections.deque([K - 1])
ans[K - 1] = 0
while queue:
    edge = queue.pop()
    for node in List[edge]:
        index, cost = node
        if ans[index] > 0:
            continue
        ans[index] = ans[edge] + cost
        queue.append(index)
for i in range(Q):
    x, y = list(map(int, input().split()))
    print((ans[x - 1] + ans[y - 1]))

import sys

input = sys.stdin.readline
N = int(eval(input()))
List = [[] for _ in range(N)]
ans = [-1] * N
for i in range(N - 1):
    a, b, c = list(map(int, input().split()))
    List[a - 1].append((b - 1, c))
    List[b - 1].append((a - 1, c))
Q, K = list(map(int, input().split()))
queue = [K - 1]
ans[K - 1] = 0
while queue:
    edge = queue.pop()
    for node in List[edge]:
        index, cost = node
        if ans[index] > 0:
            continue
        ans[index] = ans[edge] + cost
        queue.append(index)
for i in range(Q):
    x, y = list(map(int, input().split()))
    print((ans[x - 1] + ans[y - 1]))

-import collections +import sys +input = sys.stdin.readline -queue = collections.deque([K - 1]) +queue = [K - 1]