N=int(eval(input()))

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

for _ in range(N-1):

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

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

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



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

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





#DFS

stack=[(K,0)]

dist=[0]*(N+1)

dist[K]=0

while stack:

    n,c=stack.pop()

    for to,cost in E[n]:

        if dist[to]:

            continue

        dist[to]=c+cost

        stack.append((to,c+cost))



for x,y in qs:

    print((dist[x]+dist[y]))
import sys

def main():

    input = sys.stdin.readline

    N = int(eval(input()))

    G=[[] for _ in range(N)]

    for _ in range(N-1):

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

        a,b=a-1,b-1

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

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

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

    K-=1



    dfromK = [-1] * N

    dfromK[K] = 0

    stk = [(K,0)]

    while stk:

        v,d=stk.pop()

        for to,c in G[v]:

            if dfromK[to] >= 0: continue

            dfromK[to] = d+c

            stk.append((to,d+c))



    for _ in range(Q):

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

        x,y=x-1,y-1

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



if __name__ == '__main__':

    main()

N = int(eval(input()))
E = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    E[a].append((b, c))
    E[b].append((a, c))
Q, K = list(map(int, input().split()))
qs = [tuple(map(int, input().split())) for _ in range(Q)]
# DFS
stack = [(K, 0)]
dist = [0] * (N + 1)
dist[K] = 0
while stack:
    n, c = stack.pop()
    for to, cost in E[n]:
        if dist[to]:
            continue
        dist[to] = c + cost
        stack.append((to, c + cost))
for x, y in qs:
    print((dist[x] + dist[y]))

import sys


def main():
    input = sys.stdin.readline
    N = int(eval(input()))
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b, c = list(map(int, input().split()))
        a, b = a - 1, b - 1
        G[a].append((b, c))
        G[b].append((a, c))
    Q, K = list(map(int, input().split()))
    K -= 1
    dfromK = [-1] * N
    dfromK[K] = 0
    stk = [(K, 0)]
    while stk:
        v, d = stk.pop()
        for to, c in G[v]:
            if dfromK[to] >= 0:
                continue
            dfromK[to] = d + c
            stk.append((to, d + c))
    for _ in range(Q):
        x, y = list(map(int, input().split()))
        x, y = x - 1, y - 1
        print((dfromK[x] + dfromK[y]))


if __name__ == "__main__":
    main()

-N = int(eval(input())) -E = [[] for _ in range(N + 1)] -for _ in range(N - 1): -    a, b, c = list(map(int, input().split())) -    E[a].append((b, c)) -    E[b].append((a, c)) -Q, K = list(map(int, input().split())) -qs = [tuple(map(int, input().split())) for _ in range(Q)] -# DFS -stack = [(K, 0)] -dist = [0] * (N + 1) -dist[K] = 0 -while stack: -    n, c = stack.pop() -    for to, cost in E[n]: -        if dist[to]: -            continue -        dist[to] = c + cost -        stack.append((to, c + cost)) -for x, y in qs: -    print((dist[x] + dist[y])) +import sys + + +def main(): +    input = sys.stdin.readline +    N = int(eval(input())) +    G = [[] for _ in range(N)] +    for _ in range(N - 1): +        a, b, c = list(map(int, input().split())) +        a, b = a - 1, b - 1 +        G[a].append((b, c)) +        G[b].append((a, c)) +    Q, K = list(map(int, input().split())) +    K -= 1 +    dfromK = [-1] * N +    dfromK[K] = 0 +    stk = [(K, 0)] +    while stk: +        v, d = stk.pop() +        for to, c in G[v]: +            if dfromK[to] >= 0: +                continue +            dfromK[to] = d + c +            stk.append((to, d + c)) +    for _ in range(Q): +        x, y = list(map(int, input().split())) +        x, y = x - 1, y - 1 +        print((dfromK[x] + dfromK[y])) + + +if __name__ == "__main__": +    main()