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



N = int(eval(input()))

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

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

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



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

depth = [None]*(N+1)

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))



N = int(eval(input()))

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)]



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

depth = [None]*(N+1)

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))
N = int(eval(input()))
ABC = [list(map(int, input().split())) for _ in range(N - 1)]
Q, K = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(Q)]
tree = [[] for _ in range(N + 1)]
depth = [None] * (N + 1)
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))
N = int(eval(input()))
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)]
tree = [[] for _ in range(N + 1)]
depth = [None] * (N + 1)
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]]))

-ABC = [list(map(int, input().split())) for _ in range(N - 1)] +ABC = [tuple(map(int, input().split())) for _ in range(N - 1)] -XY = [list(map(int, input().split())) for _ in range(Q)] +XY = [tuple(map(int, input().split())) for _ in range(Q)] -    tree[abc[0]].append([abc[1], abc[2]]) -    tree[abc[1]].append([abc[0], abc[2]]) +    tree[abc[0]].append((abc[1], abc[2])) +    tree[abc[1]].append((abc[0], abc[2]))