from collections import deque

n=int(eval(input()))

con=[[] for _ in range(n)]

dist_f_k=[0]*n



for _ in range(n-1):

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

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

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



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

que=deque([k-1])

while que:

	cur=que.popleft()

	for nxt,dd in con[cur]:

		if dist_f_k[nxt]==0 and nxt!=k-1:

			que.append(nxt)

			dist_f_k[nxt]=dist_f_k[cur]+dd



for _ in range(q):

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

	print((dist_f_k[x-1]+dist_f_k[y-1]))
from collections import deque

n,*t=list(map(int,open(0).read().split()))

con=[[] for _ in range(n)]

dist_f_k=[0]*n



for a,b,c in zip(t[:3*n-3:3],t[1::3],t[2::3]):

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

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



k=t[3*n-2]

que=deque([k-1])

while que:

	cur=que.popleft()

	for nxt,dd in con[cur]:

		if dist_f_k[nxt]==0 and nxt!=k-1:

			que.append(nxt)

			dist_f_k[nxt]=dist_f_k[cur]+dd



for x,y in zip(t[3*n-1::2],t[3*n::2]):

	print((dist_f_k[x-1]+dist_f_k[y-1]))
from collections import deque

n = int(eval(input()))
con = [[] for _ in range(n)]
dist_f_k = [0] * n
for _ in range(n - 1):
    a, b, c = list(map(int, input().split()))
    con[a - 1].append((b - 1, c))
    con[b - 1].append((a - 1, c))
q, k = list(map(int, input().split()))
que = deque([k - 1])
while que:
    cur = que.popleft()
    for nxt, dd in con[cur]:
        if dist_f_k[nxt] == 0 and nxt != k - 1:
            que.append(nxt)
            dist_f_k[nxt] = dist_f_k[cur] + dd
for _ in range(q):
    x, y = list(map(int, input().split()))
    print((dist_f_k[x - 1] + dist_f_k[y - 1]))

from collections import deque

n, *t = list(map(int, open(0).read().split()))
con = [[] for _ in range(n)]
dist_f_k = [0] * n
for a, b, c in zip(t[: 3 * n - 3 : 3], t[1::3], t[2::3]):
    con[a - 1].append((b - 1, c))
    con[b - 1].append((a - 1, c))
k = t[3 * n - 2]
que = deque([k - 1])
while que:
    cur = que.popleft()
    for nxt, dd in con[cur]:
        if dist_f_k[nxt] == 0 and nxt != k - 1:
            que.append(nxt)
            dist_f_k[nxt] = dist_f_k[cur] + dd
for x, y in zip(t[3 * n - 1 :: 2], t[3 * n :: 2]):
    print((dist_f_k[x - 1] + dist_f_k[y - 1]))

-n = int(eval(input())) +n, *t = list(map(int, open(0).read().split())) -for _ in range(n - 1): -    a, b, c = list(map(int, input().split())) +for a, b, c in zip(t[: 3 * n - 3 : 3], t[1::3], t[2::3]): -q, k = list(map(int, input().split())) +k = t[3 * n - 2] -for _ in range(q): -    x, y = list(map(int, input().split())) +for x, y in zip(t[3 * n - 1 :: 2], t[3 * n :: 2]):