import queue

N=int(eval(input()))

G=[dict() for i in range(N)]

for i in range(N-1):

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

    G[a-1][b-1]=c

    G[b-1][a-1]=c

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

x=[0 for i in range(Q)]

y=[0 for i in range(Q)]

for i in range(Q):

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

    x[i]-=1

    y[i]-=1

q=queue.Queue()

q.put(K)

dist=[-1 for i in range(N)]

dist[K]=0

while(not(q.empty())):

    r=q.get()

    for p in G[r]:

        if dist[p]!=-1:

            continue

        dist[p]=dist[r]+G[p][r]

        q.put(p)

for i in range(Q):

    print((dist[x[i]]+dist[y[i]]))

import queue

N=int(eval(input()))

G=[dict() for i in range(N)]

for i in range(N-1):

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

    G[a-1][b-1]=c

    G[b-1][a-1]=c

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

x=[0 for i in range(Q)]

y=[0 for i in range(Q)]

for i in range(Q):

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

    x[i]-=1

    y[i]-=1

q=[]

q.append(K)

dist=[-1 for i in range(N)]

dist[K]=0

while(len(q)>0):

    r=q[-1]

    q.pop()

    for p in G[r]:

        if dist[p]!=-1:

            continue

        dist[p]=dist[r]+G[p][r]

        q.append(p)

for i in range(Q):

    print((dist[x[i]]+dist[y[i]]))

import queue

N = int(eval(input()))
G = [dict() for i in range(N)]
for i in range(N - 1):
    a, b, c = list(map(int, input().split()))
    G[a - 1][b - 1] = c
    G[b - 1][a - 1] = c
Q, K = list(map(int, input().split()))
K -= 1
x = [0 for i in range(Q)]
y = [0 for i in range(Q)]
for i in range(Q):
    x[i], y[i] = list(map(int, input().split()))
    x[i] -= 1
    y[i] -= 1
q = queue.Queue()
q.put(K)
dist = [-1 for i in range(N)]
dist[K] = 0
while not (q.empty()):
    r = q.get()
    for p in G[r]:
        if dist[p] != -1:
            continue
        dist[p] = dist[r] + G[p][r]
        q.put(p)
for i in range(Q):
    print((dist[x[i]] + dist[y[i]]))

import queue

N = int(eval(input()))
G = [dict() for i in range(N)]
for i in range(N - 1):
    a, b, c = list(map(int, input().split()))
    G[a - 1][b - 1] = c
    G[b - 1][a - 1] = c
Q, K = list(map(int, input().split()))
K -= 1
x = [0 for i in range(Q)]
y = [0 for i in range(Q)]
for i in range(Q):
    x[i], y[i] = list(map(int, input().split()))
    x[i] -= 1
    y[i] -= 1
q = []
q.append(K)
dist = [-1 for i in range(N)]
dist[K] = 0
while len(q) > 0:
    r = q[-1]
    q.pop()
    for p in G[r]:
        if dist[p] != -1:
            continue
        dist[p] = dist[r] + G[p][r]
        q.append(p)
for i in range(Q):
    print((dist[x[i]] + dist[y[i]]))

-q = queue.Queue() -q.put(K) +q = [] +q.append(K) -while not (q.empty()): -    r = q.get() +while len(q) > 0: +    r = q[-1] +    q.pop() -        q.put(p) +        q.append(p)