import sys

input = sys.stdin.readline



from collections import deque



N = int(eval(input()))



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

for _ in range(N - 1):

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

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

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

distance = [-1] * (N + 1)



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

distance = [-1] * (N + 1)

distance[K] = 0

que = deque()

q_append = que.append

for i in graph[K]:

    q_append(i)



q_left = que.popleft

while len(que) != 0:

    for _ in range(len(que)):

        abc = q_left()

        if distance[abc[0]] == -1: #動き先の値がまだ決まっていないとき

            distance[abc[0]] = distance[abc[1]] + abc[2]

            for j in graph[abc[0]]:

                q_append(j)

# print (distance)



for _ in range(Q):

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

    print((distance[x] + distance[y]))
import sys

input = sys.stdin.readline

sys.setrecursionlimit(10 ** 9)

MOD = 10 ** 9 + 7



N = int(eval(input()))



G = [[] for _ in range(N + 1)]

for _ in range(N - 1):

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

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

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



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



d = [-1] * (N + 1)

d[K] = 0

stack = [K]

while stack:

    now = stack.pop()

    for tmp in G[now]:

        next_ = tmp[0]

        if d[next_] == -1:

            d[next_] = d[now] + tmp[1]

            stack.append(next_)



for _ in range(Q):

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

    print((d[x] + d[y]))
import sys

input = sys.stdin.readline
from collections import deque

N = int(eval(input()))
graph = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    graph[a].append([b, a, c])
    graph[b].append([a, b, c])
distance = [-1] * (N + 1)
Q, K = list(map(int, input().split()))
distance = [-1] * (N + 1)
distance[K] = 0
que = deque()
q_append = que.append
for i in graph[K]:
    q_append(i)
q_left = que.popleft
while len(que) != 0:
    for _ in range(len(que)):
        abc = q_left()
        if distance[abc[0]] == -1:  # 動き先の値がまだ決まっていないとき
            distance[abc[0]] = distance[abc[1]] + abc[2]
            for j in graph[abc[0]]:
                q_append(j)
# print (distance)
for _ in range(Q):
    x, y = list(map(int, input().split()))
    print((distance[x] + distance[y]))

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9 + 7
N = int(eval(input()))
G = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    G[a].append((b, c))
    G[b].append((a, c))
Q, K = list(map(int, input().split()))
d = [-1] * (N + 1)
d[K] = 0
stack = [K]
while stack:
    now = stack.pop()
    for tmp in G[now]:
        next_ = tmp[0]
        if d[next_] == -1:
            d[next_] = d[now] + tmp[1]
            stack.append(next_)
for _ in range(Q):
    x, y = list(map(int, input().split()))
    print((d[x] + d[y]))

-from collections import deque - +sys.setrecursionlimit(10**9) +MOD = 10**9 + 7 -graph = [[] for _ in range(N + 1)] +G = [[] for _ in range(N + 1)] -    graph[a].append([b, a, c]) -    graph[b].append([a, b, c]) -distance = [-1] * (N + 1) +    G[a].append((b, c)) +    G[b].append((a, c)) -distance = [-1] * (N + 1) -distance[K] = 0 -que = deque() -q_append = que.append -for i in graph[K]: -    q_append(i) -q_left = que.popleft -while len(que) != 0: -    for _ in range(len(que)): -        abc = q_left() -        if distance[abc[0]] == -1:  # 動き先の値がまだ決まっていないとき -            distance[abc[0]] = distance[abc[1]] + abc[2] -            for j in graph[abc[0]]: -                q_append(j) -# print (distance) +d = [-1] * (N + 1) +d[K] = 0 +stack = [K] +while stack: +    now = stack.pop() +    for tmp in G[now]: +        next_ = tmp[0] +        if d[next_] == -1: +            d[next_] = d[now] + tmp[1] +            stack.append(next_) -    print((distance[x] + distance[y])) +    print((d[x] + d[y]))