n=int(eval(input()))

G=[[] for i in range(n)]

for i in range(n-1):

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

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

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

q,k=list(map(int,input().split()))

k=k-1

stack=[k]

dis=[-1]*n

dis[k]=0

while stack!=[]:

    new=[]

    for j in stack:

        d=dis[j]

        for i in G[j]:

            if dis[i[0]]==-1:

                dis[i[0]]=d+i[1]

                new.append(i[0])

    stack=new

for i in range(q):

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

    x=x-1

    y=y-1

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



import sys

input = sys.stdin.readline



n = int(eval(input()))

connect_list = [[] for i in range(n)]

for i in range(n-1):

    a, b, c = [ int(v)-1 for v in input().split() ]

    c += 1

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

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





q, k = [ int(v) for v in input().split() ]

k -= 1



shortest_list = [-1 for i in range(n)]

shortest_list[k] = 0



searching_list = [k]



while searching_list != []:



    new_search_list = []

    for i in searching_list:

        for j in connect_list[i]:

            x, y = j

            if shortest_list[x] == -1:

                shortest_list[x] = y + shortest_list[i]

                new_search_list.append(x)

    searching_list = new_search_list





for i in range(q):

    a, b = [ int(v)-1 for v in input().split() ]

    print((shortest_list[a] + shortest_list[b]))

n = int(eval(input()))
G = [[] for i in range(n)]
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    G[a - 1].append((b - 1, c))
    G[b - 1].append((a - 1, c))
q, k = list(map(int, input().split()))
k = k - 1
stack = [k]
dis = [-1] * n
dis[k] = 0
while stack != []:
    new = []
    for j in stack:
        d = dis[j]
        for i in G[j]:
            if dis[i[0]] == -1:
                dis[i[0]] = d + i[1]
                new.append(i[0])
    stack = new
for i in range(q):
    x, y = list(map(int, input().split()))
    x = x - 1
    y = y - 1
    print((dis[x] + dis[y]))

import sys

input = sys.stdin.readline
n = int(eval(input()))
connect_list = [[] for i in range(n)]
for i in range(n - 1):
    a, b, c = [int(v) - 1 for v in input().split()]
    c += 1
    connect_list[a].append((b, c))
    connect_list[b].append((a, c))
q, k = [int(v) for v in input().split()]
k -= 1
shortest_list = [-1 for i in range(n)]
shortest_list[k] = 0
searching_list = [k]
while searching_list != []:
    new_search_list = []
    for i in searching_list:
        for j in connect_list[i]:
            x, y = j
            if shortest_list[x] == -1:
                shortest_list[x] = y + shortest_list[i]
                new_search_list.append(x)
    searching_list = new_search_list
for i in range(q):
    a, b = [int(v) - 1 for v in input().split()]
    print((shortest_list[a] + shortest_list[b]))

+import sys + +input = sys.stdin.readline -G = [[] for i in range(n)] +connect_list = [[] for i in range(n)] -    a, b, c = list(map(int, input().split())) -    G[a - 1].append((b - 1, c)) -    G[b - 1].append((a - 1, c)) -q, k = list(map(int, input().split())) -k = k - 1 -stack = [k] -dis = [-1] * n -dis[k] = 0 -while stack != []: -    new = [] -    for j in stack: -        d = dis[j] -        for i in G[j]: -            if dis[i[0]] == -1: -                dis[i[0]] = d + i[1] -                new.append(i[0]) -    stack = new +    a, b, c = [int(v) - 1 for v in input().split()] +    c += 1 +    connect_list[a].append((b, c)) +    connect_list[b].append((a, c)) +q, k = [int(v) for v in input().split()] +k -= 1 +shortest_list = [-1 for i in range(n)] +shortest_list[k] = 0 +searching_list = [k] +while searching_list != []: +    new_search_list = [] +    for i in searching_list: +        for j in connect_list[i]: +            x, y = j +            if shortest_list[x] == -1: +                shortest_list[x] = y + shortest_list[i] +                new_search_list.append(x) +    searching_list = new_search_list -    x, y = list(map(int, input().split())) -    x = x - 1 -    y = y - 1 -    print((dis[x] + dis[y])) +    a, b = [int(v) - 1 for v in input().split()] +    print((shortest_list[a] + shortest_list[b]))