import queue



from sys import stdin

input = stdin.readline



N = int(input())

tree = [[] for _ in range(N)]



for i in range(N-1):

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

    a -= 1; b -= 1;

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

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



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

K -= 1



d = [float("inf") for _ in range(N)]



def dijkstra(s):

    que = queue.PriorityQueue()

    d[s] = 0

    que.put([0, s])



    while not que.empty():

        p = que.get()

        v = p[1]

        if d[v] < p[0]:

            continue

        for i, j in tree[v]:

            if d[i] > d[v] + j:

                d[i] = d[v] + j

                que.put([d[i], i])



dijkstra(K)



for i in range(Q):

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

    x -= 1; y -= 1

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

#!/usr/bin/env python2

# -*- coding: utf-8 -*-



import sys



sys.setrecursionlimit(200000)



N = int(input())

tree = [[] for _ in range(N)]



for i in range(N-1):

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

    a -= 1; b -= 1;

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

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



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

K -= 1



depth = [0 for _ in range(N)]



def dfs(v, p = -1, d = 0):

    depth[v] = d

    for i, j in tree[v]:

        if i == p:

            continue

        dfs(i, v, d + j)



dfs(K)



for i in range(Q):

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

    x -= 1; y -= 1

    print(depth[x] + depth[y])
import queue
from sys import stdin

input = stdin.readline
N = int(input())
tree = [[] for _ in range(N)]
for i in range(N - 1):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    tree[a].append((b, c))
    tree[b].append((a, c))
Q, K = list(map(int, input().split()))
K -= 1
d = [float("inf") for _ in range(N)]


def dijkstra(s):
    que = queue.PriorityQueue()
    d[s] = 0
    que.put([0, s])
    while not que.empty():
        p = que.get()
        v = p[1]
        if d[v] < p[0]:
            continue
        for i, j in tree[v]:
            if d[i] > d[v] + j:
                d[i] = d[v] + j
                que.put([d[i], i])


dijkstra(K)
for i in range(Q):
    x, y = list(map(int, input().split()))
    x -= 1
    y -= 1
    print(d[x] + d[y])

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys

sys.setrecursionlimit(200000)
N = int(input())
tree = [[] for _ in range(N)]
for i in range(N - 1):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    tree[a].append((b, c))
    tree[b].append((a, c))
Q, K = list(map(int, input().split()))
K -= 1
depth = [0 for _ in range(N)]


def dfs(v, p=-1, d=0):
    depth[v] = d
    for i, j in tree[v]:
        if i == p:
            continue
        dfs(i, v, d + j)


dfs(K)
for i in range(Q):
    x, y = list(map(int, input().split()))
    x -= 1
    y -= 1
    print(depth[x] + depth[y])

-import queue -from sys import stdin +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +import sys -input = stdin.readline +sys.setrecursionlimit(200000) -d = [float("inf") for _ in range(N)] +depth = [0 for _ in range(N)] -def dijkstra(s): -    que = queue.PriorityQueue() -    d[s] = 0 -    que.put([0, s]) -    while not que.empty(): -        p = que.get() -        v = p[1] -        if d[v] < p[0]: +def dfs(v, p=-1, d=0): +    depth[v] = d +    for i, j in tree[v]: +        if i == p: -        for i, j in tree[v]: -            if d[i] > d[v] + j: -                d[i] = d[v] + j -                que.put([d[i], i]) +        dfs(i, v, d + j) -dijkstra(K) +dfs(K) -    print(d[x] + d[y]) +    print(depth[x] + depth[y])