N = int(eval(input()))

route = [{} for _ in range(N)]

dist = [-1] * N

for i in range(N - 1):

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

    route[a-1][b-1] = d

    route[b-1][a-1] = d



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

dist[K-1] = 0

dfs_stack = [K-1]

while dfs_stack:

    s = dfs_stack.pop()

    for t, t_dist in list(route[s].items()):

        if dist[t] == -1:

            dist[t] = dist[s] + t_dist

            dfs_stack.append(t)

for i in range(Q):

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

    x, y = x - 1, y - 1

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

from collections import deque

 

n = int(eval(input()))

path = {}

for i in range(n-1):

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

    if not a in list(path.keys()):

        path[a] = [(b, c)]

    else:

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

        

    if not b in list(path.keys()):

        path[b] = [(a, c)]

    else:

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

q, k = list(map(int, input().split()))

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



dist = [None]*(n+1)

dist[k] = 0

que = deque([(k, 0)])

while len(que) > 0:

    node, d = que.popleft()

    dist[node] = d

    for node_next, d_next in path[node]:

        if dist[node_next] is None:

            que.append((node_next, d+d_next))

# print(dist)

 

for x, y in xy:

    print((dist[x]+dist[y]))
N = int(eval(input()))
route = [{} for _ in range(N)]
dist = [-1] * N
for i in range(N - 1):
    a, b, d = list(map(int, input().split()))
    route[a - 1][b - 1] = d
    route[b - 1][a - 1] = d
Q, K = list(map(int, input().split()))
dist[K - 1] = 0
dfs_stack = [K - 1]
while dfs_stack:
    s = dfs_stack.pop()
    for t, t_dist in list(route[s].items()):
        if dist[t] == -1:
            dist[t] = dist[s] + t_dist
            dfs_stack.append(t)
for i in range(Q):
    x, y = list(map(int, input().split()))
    x, y = x - 1, y - 1
    print((dist[x] + dist[y]))

from collections import deque

n = int(eval(input()))
path = {}
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    if not a in list(path.keys()):
        path[a] = [(b, c)]
    else:
        path[a].append((b, c))
    if not b in list(path.keys()):
        path[b] = [(a, c)]
    else:
        path[b].append((a, c))
q, k = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(q)]
dist = [None] * (n + 1)
dist[k] = 0
que = deque([(k, 0)])
while len(que) > 0:
    node, d = que.popleft()
    dist[node] = d
    for node_next, d_next in path[node]:
        if dist[node_next] is None:
            que.append((node_next, d + d_next))
# print(dist)
for x, y in xy:
    print((dist[x] + dist[y]))

-N = int(eval(input())) -route = [{} for _ in range(N)] -dist = [-1] * N -for i in range(N - 1): -    a, b, d = list(map(int, input().split())) -    route[a - 1][b - 1] = d -    route[b - 1][a - 1] = d -Q, K = list(map(int, input().split())) -dist[K - 1] = 0 -dfs_stack = [K - 1] -while dfs_stack: -    s = dfs_stack.pop() -    for t, t_dist in list(route[s].items()): -        if dist[t] == -1: -            dist[t] = dist[s] + t_dist -            dfs_stack.append(t) -for i in range(Q): -    x, y = list(map(int, input().split())) -    x, y = x - 1, y - 1 +from collections import deque + +n = int(eval(input())) +path = {} +for i in range(n - 1): +    a, b, c = list(map(int, input().split())) +    if not a in list(path.keys()): +        path[a] = [(b, c)] +    else: +        path[a].append((b, c)) +    if not b in list(path.keys()): +        path[b] = [(a, c)] +    else: +        path[b].append((a, c)) +q, k = list(map(int, input().split())) +xy = [list(map(int, input().split())) for _ in range(q)] +dist = [None] * (n + 1) +dist[k] = 0 +que = deque([(k, 0)]) +while len(que) > 0: +    node, d = que.popleft() +    dist[node] = d +    for node_next, d_next in path[node]: +        if dist[node_next] is None: +            que.append((node_next, d + d_next)) +# print(dist) +for x, y in xy: