import heapq

def dijkstra_heap(s):

    d = [float("inf")] * n

    used = [True] * n 

    d[s] = 0

    used[s] = False

    edgelist = []

    for e in edge[s]:

        heapq.heappush(edgelist,e)

    while len(edgelist):

        minedge = heapq.heappop(edgelist)

        if not used[minedge[1]]:

            continue

        v = minedge[1]

        d[v] = minedge[0]

        used[v] = False

        for e in edge[v]:

            if used[e[1]]:

                heapq.heappush(edgelist,[e[0]+d[v],e[1]])

    return d

import sys

input = sys.stdin.readline

n =int(eval(input()))



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

#edge[i] : [weght,to]

for i in range(n-1):

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

    a, b = a-1, b-1

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

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

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

k = k-1

d = dijkstra_heap(k)

for i in range(q):

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

  x, y = x-1, y-1

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

def dijkstra_heap(s):

    d = [float("inf")] * n

    used = [True] * n #True: not used

    d[s] = 0

    used[s] = False

    edgelist = []

    for e in edge[s]:

        heapq.heappush(edgelist,e)

    while len(edgelist):

        minedge = heapq.heappop(edgelist)

        if not used[minedge[1]]:

            continue

        v = minedge[1]

        d[v] = minedge[0]

        used[v] = False

        for e in edge[v]:

            if used[e[1]]:

                heapq.heappush(edgelist,(e[0]+d[v],e[1]))

    return d

import sys

input = sys.stdin.readline

n =int(eval(input()))

 

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

#edge[i] : [weght,to]

for i in range(n-1):

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

    a, b = a-1, b-1

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

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

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

k = k-1

d = dijkstra_heap(k)

for i in range(q):

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

  x, y = x-1, y-1

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


def dijkstra_heap(s):
    d = [float("inf")] * n
    used = [True] * n
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist, e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist, [e[0] + d[v], e[1]])
    return d


import sys

input = sys.stdin.readline
n = int(eval(input()))
edge = [[] for i in range(n)]
# edge[i] : [weght,to]
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    a, b = a - 1, b - 1
    edge[a].append([c, b])
    edge[b].append([c, a])
q, k = list(map(int, input().split()))
k = k - 1
d = dijkstra_heap(k)
for i in range(q):
    x, y = list(map(int, input().split()))
    x, y = x - 1, y - 1
    print((d[x] + d[y]))

import heapq


def dijkstra_heap(s):
    d = [float("inf")] * n
    used = [True] * n  # True: not used
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist, e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist, (e[0] + d[v], e[1]))
    return d


import sys

input = sys.stdin.readline
n = int(eval(input()))
edge = [[] for i in range(n)]
# edge[i] : [weght,to]
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    a, b = a - 1, b - 1
    edge[a].append((c, b))
    edge[b].append((c, a))
q, k = list(map(int, input().split()))
k = k - 1
d = dijkstra_heap(k)
for i in range(q):
    x, y = list(map(int, input().split()))
    x, y = x - 1, y - 1
    print((d[x] + d[y]))

-    used = [True] * n +    used = [True] * n  # True: not used -                heapq.heappush(edgelist, [e[0] + d[v], e[1]]) +                heapq.heappush(edgelist, (e[0] + d[v], e[1])) -    edge[a].append([c, b]) -    edge[b].append([c, a]) +    edge[a].append((c, b)) +    edge[b].append((c, a))