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



class edge():

    def __init__(self,_to,_cost):

        self.to = _to;

        self.cost = _cost;



N = int(eval(input()))

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



for i in range(N-1):

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

    a = a - 1

    b = b - 1

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

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

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

K = K - 1

depth = [None]*N



def DFS(v,p,d):

    depth[v] = d

    for e in tree[v]:

        if e.to == p:

            continue

        DFS(e.to, v, d + e.cost)

DFS(K,-1,0)



for _ in range(Q):

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

    x = x - 1

    y = y - 1

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

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



N = int(eval(input()))



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

depth = [None]*(N+1)



ABC = [ tuple(map(int,input().split())) for _ in range(N-1)]

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

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



for abc in ABC:

    tree[abc[0]].append((abc[1],abc[2]))

    tree[abc[1]].append((abc[0],abc[2]))



def DFS(v,p,d):

    depth[v] = d

    for e in tree[v]:

        if e[0] != p:

            DFS(e[0], v, d + e[1])



DFS(K,0,0)



for i in range(Q):

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

sys.setrecursionlimit(int(1e7))


class edge:
    def __init__(self, _to, _cost):
        self.to = _to
        self.cost = _cost


N = int(eval(input()))
tree = [[] for i in range(N + 1)]
for i in range(N - 1):
    a, b, c = list(map(int, input().split()))
    a = a - 1
    b = b - 1
    tree[a].append(edge(b, c))
    tree[b].append(edge(a, c))
Q, K = list(map(int, input().split()))
K = K - 1
depth = [None] * N


def DFS(v, p, d):
    depth[v] = d
    for e in tree[v]:
        if e.to == p:
            continue
        DFS(e.to, v, d + e.cost)


DFS(K, -1, 0)
for _ in range(Q):
    x, y = list(map(int, input().split()))
    x = x - 1
    y = y - 1
    print((depth[x] + depth[y]))

import sys

sys.setrecursionlimit(int(1e7))
N = int(eval(input()))
tree = [[] for _ in range(N + 1)]
depth = [None] * (N + 1)
ABC = [tuple(map(int, input().split())) for _ in range(N - 1)]
Q, K = list(map(int, input().split()))
XY = [tuple(map(int, input().split())) for _ in range(Q)]
for abc in ABC:
    tree[abc[0]].append((abc[1], abc[2]))
    tree[abc[1]].append((abc[0], abc[2]))


def DFS(v, p, d):
    depth[v] = d
    for e in tree[v]:
        if e[0] != p:
            DFS(e[0], v, d + e[1])


DFS(K, 0, 0)
for i in range(Q):
    print((depth[XY[i][0]] + depth[XY[i][1]]))

- - -class edge: -    def __init__(self, _to, _cost): -        self.to = _to -        self.cost = _cost - - -tree = [[] for i in range(N + 1)] -for i in range(N - 1): -    a, b, c = list(map(int, input().split())) -    a = a - 1 -    b = b - 1 -    tree[a].append(edge(b, c)) -    tree[b].append(edge(a, c)) +tree = [[] for _ in range(N + 1)] +depth = [None] * (N + 1) +ABC = [tuple(map(int, input().split())) for _ in range(N - 1)] -K = K - 1 -depth = [None] * N +XY = [tuple(map(int, input().split())) for _ in range(Q)] +for abc in ABC: +    tree[abc[0]].append((abc[1], abc[2])) +    tree[abc[1]].append((abc[0], abc[2])) -        if e.to == p: -            continue -        DFS(e.to, v, d + e.cost) +        if e[0] != p: +            DFS(e[0], v, d + e[1]) -DFS(K, -1, 0) -for _ in range(Q): -    x, y = list(map(int, input().split())) -    x = x - 1 -    y = y - 1 -    print((depth[x] + depth[y])) +DFS(K, 0, 0) +for i in range(Q): +    print((depth[XY[i][0]] + depth[XY[i][1]]))