import sys;sys.setrecursionlimit(int(1e7))

from collections import deque



N = int(eval(input()))

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

for _ in range(N-1):

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

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

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



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

XY = [tuple(map(int,input().split())) for _ in range(Qn)]



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

dist[K] = 0

Q = deque()

Q.append(K)

while len(Q):

    p = Q.popleft()

    for q,c in tree[p]:

        if dist[q] != -1: continue

        dist[q] = dist[p]+c

        Q.append(q)



for i in range(Qn):

    print((dist[XY[i][0]] + dist[XY[i][1]]))
import sys;sys.setrecursionlimit(int(1e7))

from sys import stdin

from collections import deque



input = stdin.readline

N = int(eval(input()))

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

for _ in range(N-1):

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

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

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



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

XY = [tuple(map(int,input().split())) for _ in range(Qn)]



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

dist[K] = 0

Q = deque()

Q.append(K)

while len(Q):

    p = Q.popleft()

    for q,c in tree[p]:

        if dist[q] != -1: continue

        dist[q] = dist[p]+c

        Q.append(q)



for i in range(Qn):

    print((dist[XY[i][0]] + dist[XY[i][1]]))
import sys

sys.setrecursionlimit(int(1e7))
from collections import deque

N = int(eval(input()))
tree = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    tree[a].append((b, c))
    tree[b].append((a, c))
Qn, K = list(map(int, input().split()))
XY = [tuple(map(int, input().split())) for _ in range(Qn)]
dist = [-1] * (N + 1)
dist[K] = 0
Q = deque()
Q.append(K)
while len(Q):
    p = Q.popleft()
    for q, c in tree[p]:
        if dist[q] != -1:
            continue
        dist[q] = dist[p] + c
        Q.append(q)
for i in range(Qn):
    print((dist[XY[i][0]] + dist[XY[i][1]]))

import sys

sys.setrecursionlimit(int(1e7))
from sys import stdin
from collections import deque

input = stdin.readline
N = int(eval(input()))
tree = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    tree[a].append((b, c))
    tree[b].append((a, c))
Qn, K = list(map(int, input().split()))
XY = [tuple(map(int, input().split())) for _ in range(Qn)]
dist = [-1] * (N + 1)
dist[K] = 0
Q = deque()
Q.append(K)
while len(Q):
    p = Q.popleft()
    for q, c in tree[p]:
        if dist[q] != -1:
            continue
        dist[q] = dist[p] + c
        Q.append(q)
for i in range(Qn):
    print((dist[XY[i][0]] + dist[XY[i][1]]))

+from sys import stdin +input = stdin.readline