from heapq import heappop, heappush

n = int(eval(input()))

g = [[] for _ in range(n)]



for _ 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))





def dijkstra(s,n,g):

    # g[i][j] : the cost of i→j  or g[i] = [(target, cost), ...]

    # must import heapq

    d = [10**18] * n

    d[s] = 0

    q = [(0,s)]

    while q:

        dist_u, u = heappop(q)

        if d[u] < dist_u:

            continue

        for v, c in g[u]:  # 'in g[u]' if g is an adj list.

            if d[v] > dist_u + c:

                d[v] = dist_u + c

                heappush(q, (d[v], v))

    return d









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

d = dijkstra(k-1, n, g)



for _ in range(q):

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

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

from heapq import heappop, heappush

import sys

sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline



n = int(eval(input()))

g = [[] for _ in range(n)]



for _ 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))





def dijkstra(s,n,g):

    # g[i][j] : the cost of i→j  or g[i] = [(target, cost), ...]

    # must import heapq

    d = [10**18] * n

    d[s] = 0

    q = [(0,s)]

    while q:

        dist_u, u = heappop(q)

        if d[u] < dist_u:

            continue

        for v, c in g[u]:  # 'in g[u]' if g is an adj list.

            if d[v] > dist_u + c:

                d[v] = dist_u + c

                heappush(q, (d[v], v))

    return d









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

d = dijkstra(k-1, n, g)



for _ in range(q):

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

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

from heapq import heappop, heappush

n = int(eval(input()))
g = [[] for _ in range(n)]
for _ 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))


def dijkstra(s, n, g):
    # g[i][j] : the cost of i→j  or g[i] = [(target, cost), ...]
    # must import heapq
    d = [10**18] * n
    d[s] = 0
    q = [(0, s)]
    while q:
        dist_u, u = heappop(q)
        if d[u] < dist_u:
            continue
        for v, c in g[u]:  # 'in g[u]' if g is an adj list.
            if d[v] > dist_u + c:
                d[v] = dist_u + c
                heappush(q, (d[v], v))
    return d


q, k = list(map(int, input().split()))
d = dijkstra(k - 1, n, g)
for _ in range(q):
    x, y = list(map(int, input().split()))
    print((d[x - 1] + d[y - 1]))

from heapq import heappop, heappush
import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n = int(eval(input()))
g = [[] for _ in range(n)]
for _ 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))


def dijkstra(s, n, g):
    # g[i][j] : the cost of i→j  or g[i] = [(target, cost), ...]
    # must import heapq
    d = [10**18] * n
    d[s] = 0
    q = [(0, s)]
    while q:
        dist_u, u = heappop(q)
        if d[u] < dist_u:
            continue
        for v, c in g[u]:  # 'in g[u]' if g is an adj list.
            if d[v] > dist_u + c:
                d[v] = dist_u + c
                heappush(q, (d[v], v))
    return d


q, k = list(map(int, input().split()))
d = dijkstra(k - 1, n, g)
for _ in range(q):
    x, y = list(map(int, input().split()))
    print((d[x - 1] + d[y - 1]))

+import sys +sys.setrecursionlimit(10**7) +input = sys.stdin.readline