import sys

from collections import *

import heapq

import math

import bisect

from itertools import permutations,accumulate,combinations,product

from fractions import gcd

def input():

    return sys.stdin.readline()[:-1]

mod=10**9+7



n=int(eval(input()))

abc=[list(map(int,input().split())) for i in range(n-1)]

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

xy=[list(map(int,input().split())) for i in range(q)]



lst=[[] for i in range(n+1)]

# print(lst)

for i in range(n-1):

    a,b,c=abc[i]

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

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

dist=[float('inf')]*(n+1)

# dist[k]=0

# print(lst)

d=deque()

d.append([[[k,0]],0])

while d:

    tmp=d.popleft()

    # print(tmp)

    for i in range(len(tmp[0])):

        # print(tmp[0][i])

        if dist[tmp[0][i][0]]==float('inf'):

            dist[tmp[0][i][0]]=tmp[0][i][1]+tmp[-1]

            d.append([lst[tmp[0][i][0]],dist[tmp[0][i][0]]])

# print(dist)

for i in range(q):

    x,y=xy[i]

    print((dist[x]+dist[y]))
import bisect, copy, heapq, math, sys

from collections import *

from functools import lru_cache

from itertools import accumulate, combinations, permutations, product

def input():

    return sys.stdin.readline()[:-1]

def ruiseki(lst):

    return [0]+list(accumulate(lst))

def celi(a,b):

    return -(-a//b)

sys.setrecursionlimit(5000000)

mod=pow(10,9)+7

al=[chr(ord('a') + i) for i in range(26)]

direction=[[1,0],[0,1],[-1,0],[0,-1]]



n=int(eval(input()))

abc=[list(map(int,input().split())) for i in range(n-1)]

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

xy=[list(map(int,input().split())) for i in range(q)]



itta=[0]*(n+1)

dic=defaultdict(list)

for a,b,c in abc:

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

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



d=deque([(k,0)])

while d:

    now=d.popleft()

    if itta[now[0]]!=0:

        continue

    itta[now[0]]=now[1]

    for i,j in dic[now[0]]:

        d.append((i,j+now[1]))

# print(itta)

itta[k]=0

for x,y in xy:

    print((itta[x]+itta[y]))
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations, accumulate, combinations, product
from fractions import gcd


def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7
n = int(eval(input()))
abc = [list(map(int, input().split())) for i in range(n - 1)]
q, k = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(q)]
lst = [[] for i in range(n + 1)]
# print(lst)
for i in range(n - 1):
    a, b, c = abc[i]
    lst[a].append([b, c])
    lst[b].append([a, c])
dist = [float("inf")] * (n + 1)
# dist[k]=0
# print(lst)
d = deque()
d.append([[[k, 0]], 0])
while d:
    tmp = d.popleft()
    # print(tmp)
    for i in range(len(tmp[0])):
        # print(tmp[0][i])
        if dist[tmp[0][i][0]] == float("inf"):
            dist[tmp[0][i][0]] = tmp[0][i][1] + tmp[-1]
            d.append([lst[tmp[0][i][0]], dist[tmp[0][i][0]]])
# print(dist)
for i in range(q):
    x, y = xy[i]
    print((dist[x] + dist[y]))

import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product


def input():
    return sys.stdin.readline()[:-1]


def ruiseki(lst):
    return [0] + list(accumulate(lst))


def celi(a, b):
    return -(-a // b)


sys.setrecursionlimit(5000000)
mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
n = int(eval(input()))
abc = [list(map(int, input().split())) for i in range(n - 1)]
q, k = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(q)]
itta = [0] * (n + 1)
dic = defaultdict(list)
for a, b, c in abc:
    dic[a].append((b, c))
    dic[b].append((a, c))
d = deque([(k, 0)])
while d:
    now = d.popleft()
    if itta[now[0]] != 0:
        continue
    itta[now[0]] = now[1]
    for i, j in dic[now[0]]:
        d.append((i, j + now[1]))
# print(itta)
itta[k] = 0
for x, y in xy:
    print((itta[x] + itta[y]))

-import sys +import bisect, copy, heapq, math, sys -import heapq -import math -import bisect -from itertools import permutations, accumulate, combinations, product -from fractions import gcd +from functools import lru_cache +from itertools import accumulate, combinations, permutations, product -mod = 10**9 + 7 +def ruiseki(lst): +    return [0] + list(accumulate(lst)) + + +def celi(a, b): +    return -(-a // b) + + +sys.setrecursionlimit(5000000) +mod = pow(10, 9) + 7 +al = [chr(ord("a") + i) for i in range(26)] +direction = [[1, 0], [0, 1], [-1, 0], [0, -1]] -lst = [[] for i in range(n + 1)] -# print(lst) -for i in range(n - 1): -    a, b, c = abc[i] -    lst[a].append([b, c]) -    lst[b].append([a, c]) -dist = [float("inf")] * (n + 1) -# dist[k]=0 -# print(lst) -d = deque() -d.append([[[k, 0]], 0]) +itta = [0] * (n + 1) +dic = defaultdict(list) +for a, b, c in abc: +    dic[a].append((b, c)) +    dic[b].append((a, c)) +d = deque([(k, 0)]) -    tmp = d.popleft() -    # print(tmp) -    for i in range(len(tmp[0])): -        # print(tmp[0][i]) -        if dist[tmp[0][i][0]] == float("inf"): -            dist[tmp[0][i][0]] = tmp[0][i][1] + tmp[-1] -            d.append([lst[tmp[0][i][0]], dist[tmp[0][i][0]]]) -# print(dist) -for i in range(q): -    x, y = xy[i] -    print((dist[x] + dist[y])) +    now = d.popleft() +    if itta[now[0]] != 0: +        continue +    itta[now[0]] = now[1] +    for i, j in dic[now[0]]: +        d.append((i, j + now[1])) +# print(itta) +itta[k] = 0 +for x, y in xy: +    print((itta[x] + itta[y]))