## abc070d: Transit Tree Path



from collections import deque



n = int(eval(input()))



T = [{} for _ in range(n)]

for _ in range(n-1):

    v1,v2,d = list(map(int, input().split()))

    T[v1-1][v2-1] = d

    T[v2-1][v1-1] = d



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



visit = [False]*n

depth = [0]*n

que = deque()

que.append(k-1)

while que:

    p = que.popleft()

    visit[p] = True

    for c in list(T[p].keys()):

        if visit[c]: continue

        depth[c] = depth[p] + T[p][c]

        que.append(c)



for _ in range(q):

    v1,v2 = list(map(int, input().split()))

    print((depth[v1-1]+depth[v2-1]))
## abc070d: Transit Tree Path

import sys

from collections import deque

input = sys.stdin.readline



n = int(eval(input()))



T = [{} for _ in range(n)]

for _ in range(n-1):

    v1,v2,d = list(map(int, input().split()))

    T[v1-1][v2-1] = d

    T[v2-1][v1-1] = d



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



visit = [False]*n

depth = [0]*n

que = deque()

que.append(k-1)

while que:

    p = que.popleft()

    visit[p] = True

    for c in list(T[p].keys()):

        if visit[c]: continue

        depth[c] = depth[p] + T[p][c]

        que.append(c)



for _ in range(q):

    v1,v2 = list(map(int, input().split()))

    print((depth[v1-1]+depth[v2-1]))
## abc070d: Transit Tree Path
from collections import deque

n = int(eval(input()))
T = [{} for _ in range(n)]
for _ in range(n - 1):
    v1, v2, d = list(map(int, input().split()))
    T[v1 - 1][v2 - 1] = d
    T[v2 - 1][v1 - 1] = d
q, k = list(map(int, input().split()))
visit = [False] * n
depth = [0] * n
que = deque()
que.append(k - 1)
while que:
    p = que.popleft()
    visit[p] = True
    for c in list(T[p].keys()):
        if visit[c]:
            continue
        depth[c] = depth[p] + T[p][c]
        que.append(c)
for _ in range(q):
    v1, v2 = list(map(int, input().split()))
    print((depth[v1 - 1] + depth[v2 - 1]))

## abc070d: Transit Tree Path
import sys
from collections import deque

input = sys.stdin.readline
n = int(eval(input()))
T = [{} for _ in range(n)]
for _ in range(n - 1):
    v1, v2, d = list(map(int, input().split()))
    T[v1 - 1][v2 - 1] = d
    T[v2 - 1][v1 - 1] = d
q, k = list(map(int, input().split()))
visit = [False] * n
depth = [0] * n
que = deque()
que.append(k - 1)
while que:
    p = que.popleft()
    visit[p] = True
    for c in list(T[p].keys()):
        if visit[c]:
            continue
        depth[c] = depth[p] + T[p][c]
        que.append(c)
for _ in range(q):
    v1, v2 = list(map(int, input().split()))
    print((depth[v1 - 1] + depth[v2 - 1]))

+import sys +input = sys.stdin.readline