import sys

sys.setrecursionlimit(10**9)



N = int(eval(input()))

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



for _ in range(N-1) :

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

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

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



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



dist = [None]*(N+1)



def dfs(now,d) :

    dist[now] = d

    for to,c in T[now] :

        if dist[to] is not None :

            continue

        dfs(to,d+c)



dfs(K,0)



for _ in range(Q) :

    u,v = list(map(int,input().split()))

    print((dist[u] + dist[v]))

    
import sys

sys.setrecursionlimit(10**9)



input = sys.stdin.readline



N = int(input())



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



for _ in range(N-1) :

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

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

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



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



dist = [None]*(N+1)



def dfs(now,d) :

    dist[now] = d

    for to,c in T[now] :

        if dist[to] is not None :

            continue

        dfs(to,d+c)



dfs(K,0)



ans = [0]*Q



for i in range(Q) :

    u,v = map(int,input().split())

    ans[i] = dist[u]+dist[v]



print(*ans,sep="\n")



import sys

sys.setrecursionlimit(10**9)
N = int(eval(input()))
T = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    T[a].append([b, c])
    T[b].append([a, c])
Q, K = list(map(int, input().split()))
dist = [None] * (N + 1)


def dfs(now, d):
    dist[now] = d
    for to, c in T[now]:
        if dist[to] is not None:
            continue
        dfs(to, d + c)


dfs(K, 0)
for _ in range(Q):
    u, v = list(map(int, input().split()))
    print((dist[u] + dist[v]))

import sys

sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N = int(input())
T = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    T[a].append([b, c])
    T[b].append([a, c])
Q, K = map(int, input().split())
dist = [None] * (N + 1)


def dfs(now, d):
    dist[now] = d
    for to, c in T[now]:
        if dist[to] is not None:
            continue
        dfs(to, d + c)


dfs(K, 0)
ans = [0] * Q
for i in range(Q):
    u, v = map(int, input().split())
    ans[i] = dist[u] + dist[v]
print(*ans, sep="\n")

-N = int(eval(input())) +input = sys.stdin.readline +N = int(input()) -    a, b, c = list(map(int, input().split())) +    a, b, c = map(int, input().split()) -Q, K = list(map(int, input().split())) +Q, K = map(int, input().split()) -for _ in range(Q): -    u, v = list(map(int, input().split())) -    print((dist[u] + dist[v])) +ans = [0] * Q +for i in range(Q): +    u, v = map(int, input().split()) +    ans[i] = dist[u] + dist[v] +print(*ans, sep="\n")