#!/usr/bin/env python2

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



import queue



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 -*-



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

    St = []

    St.append([v, p, d])

    # 空のシーケンスは偽になる

    while St:

        cur = St.pop()

        depth[cur[0]] = cur[2]

        for i, j in tree[cur[0]]:

            if i == cur[1]:

                continue

            St.append([i, cur[0], cur[2] + j])



dfs(K)



for i in range(Q):

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

    x -= 1; y -= 1

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

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

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 -*-
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):
    St = []
    St.append([v, p, d])
    # 空のシーケンスは偽になる
    while St:
        cur = St.pop()
        depth[cur[0]] = cur[2]
        for i, j in tree[cur[0]]:
            if i == cur[1]:
                continue
            St.append([i, cur[0], cur[2] + 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 - -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]: -            continue -        for i, j in tree[v]: -            if d[i] > d[v] + j: -                d[i] = d[v] + j -                que.put([d[i], i]) +def dfs(v, p=-1, d=0): +    St = [] +    St.append([v, p, d]) +    # 空のシーケンスは偽になる +    while St: +        cur = St.pop() +        depth[cur[0]] = cur[2] +        for i, j in tree[cur[0]]: +            if i == cur[1]: +                continue +            St.append([i, cur[0], cur[2] + j]) -dijkstra(K) +dfs(K) -    print(d[x] + d[y]) +    print(depth[x] + depth[y])