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



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