import sys



sys.setrecursionlimit(10**6)



input = sys.stdin.readline



n = int(eval(input()))

ls = [list(map(int, input().split())) for _ in range(n - 1)]



es = [[] for _ in range(n + 1)]

for a, b, c in ls:

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

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

ds = [0] * (n + 1)





def dfs(cur, prev, c):

    ds[cur] = ds[prev] + c

    for e, c in es[cur]:

        if e != prev:

            dfs(e, cur, c)





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

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



dfs(k, k, 0)

for x, y in qs:

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



sys.setrecursionlimit(10**6)



input = sys.stdin.readline



n = int(eval(input()))



es = [[] for _ in range(n + 1)]

for _ in range(n - 1):

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

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

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

ds = [0] * (n + 1)





def dfs(cur, prev, c):

    ds[cur] = ds[prev] + c

    for e, c in es[cur]:

        if e != prev:

            dfs(e, cur, c)





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



dfs(k, k, 0)

for _ in range(q):

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

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

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
n = int(eval(input()))
ls = [list(map(int, input().split())) for _ in range(n - 1)]
es = [[] for _ in range(n + 1)]
for a, b, c in ls:
    es[a].append((b, c))
    es[b].append((a, c))
ds = [0] * (n + 1)


def dfs(cur, prev, c):
    ds[cur] = ds[prev] + c
    for e, c in es[cur]:
        if e != prev:
            dfs(e, cur, c)


q, k = list(map(int, input().split()))
qs = [list(map(int, input().split())) for _ in range(q)]
dfs(k, k, 0)
for x, y in qs:
    print((ds[x] + ds[y]))

import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.readline
n = int(eval(input()))
es = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b, c = list(map(int, input().split()))
    es[a].append((b, c))
    es[b].append((a, c))
ds = [0] * (n + 1)


def dfs(cur, prev, c):
    ds[cur] = ds[prev] + c
    for e, c in es[cur]:
        if e != prev:
            dfs(e, cur, c)


q, k = list(map(int, input().split()))
dfs(k, k, 0)
for _ in range(q):
    x, y = list(map(int, input().split()))
    print((ds[x] + ds[y]))

-ls = [list(map(int, input().split())) for _ in range(n - 1)] -for a, b, c in ls: +for _ in range(n - 1): +    a, b, c = list(map(int, input().split())) -qs = [list(map(int, input().split())) for _ in range(q)] -for x, y in qs: +for _ in range(q): +    x, y = list(map(int, input().split()))