def dfs(k, path, n):

    """連結情報path,頂点の個数Nが与えられたとき

    頂点Kから各頂点までの距離をlistで返す"""

    from collections import deque # deque(),popleft()

    dist = [-1] * n

    dist[k] = 0

    que = deque([])

    que.append(k)

    while que:

        label = que.popleft()

        for i,c in path[label]: # 頂点labelと連結している頂点iと距離c

            if dist[i] == -1:

                dist[i] = dist[label] + c

                que += [i] # 次に調べる頂点に

    return dist



n = int(eval(input()))

path = [[] for i in range(n)]

# path = [{1,2}] * 3

# print(path)

for i in range(n-1):

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

#     print(a,b,c)

    path[a-1] += [(b-1, c)]

    path[b-1] += [(a-1, c)]



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

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

dis = dfs(k-1, path, n)

for i in range(q):

    print((dis[xy[i][0] - 1] + dis[xy[i][1] - 1]))

from sys import stdin

input = stdin.readline



def dfs(k, path, n):

    """連結情報path,頂点の個数Nが与えられたとき

    頂点Kから各頂点までの距離をlistで返す"""

    from collections import deque # deque(),popleft()

    dist = [-1] * n

    dist[k] = 0

    que = deque([])

    que.append(k)

    while que:

        label = que.popleft()

        for i,c in path[label]: # 頂点labelと連結している頂点iと距離c

            if dist[i] == -1:

                dist[i] = dist[label] + c

                que += [i] # 次に調べる頂点に

    return dist



n = int(eval(input()))

path = [[] for i in range(n)]

# path = [{1,2}] * 3

# print(path)

for i in range(n-1):

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

#     print(a,b,c)

    path[a-1] += [(b-1, c)]

    path[b-1] += [(a-1, c)]



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

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

dis = dfs(k-1, path, n)

for i in range(q):

    print((dis[xy[i][0] - 1] + dis[xy[i][1] - 1]))

def dfs(k, path, n):
    """連結情報path,頂点の個数Nが与えられたとき
    頂点Kから各頂点までの距離をlistで返す"""
    from collections import deque  # deque(),popleft()

    dist = [-1] * n
    dist[k] = 0
    que = deque([])
    que.append(k)
    while que:
        label = que.popleft()
        for i, c in path[label]:  # 頂点labelと連結している頂点iと距離c
            if dist[i] == -1:
                dist[i] = dist[label] + c
                que += [i]  # 次に調べる頂点に
    return dist


n = int(eval(input()))
path = [[] for i in range(n)]
# path = [{1,2}] * 3
# print(path)
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    #     print(a,b,c)
    path[a - 1] += [(b - 1, c)]
    path[b - 1] += [(a - 1, c)]
q, k = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(q)]
dis = dfs(k - 1, path, n)
for i in range(q):
    print((dis[xy[i][0] - 1] + dis[xy[i][1] - 1]))

from sys import stdin

input = stdin.readline


def dfs(k, path, n):
    """連結情報path,頂点の個数Nが与えられたとき
    頂点Kから各頂点までの距離をlistで返す"""
    from collections import deque  # deque(),popleft()

    dist = [-1] * n
    dist[k] = 0
    que = deque([])
    que.append(k)
    while que:
        label = que.popleft()
        for i, c in path[label]:  # 頂点labelと連結している頂点iと距離c
            if dist[i] == -1:
                dist[i] = dist[label] + c
                que += [i]  # 次に調べる頂点に
    return dist


n = int(eval(input()))
path = [[] for i in range(n)]
# path = [{1,2}] * 3
# print(path)
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    #     print(a,b,c)
    path[a - 1] += [(b - 1, c)]
    path[b - 1] += [(a - 1, c)]
q, k = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(q)]
dis = dfs(k - 1, path, n)
for i in range(q):
    print((dis[xy[i][0] - 1] + dis[xy[i][1] - 1]))

+from sys import stdin + +input = stdin.readline + +