from queue import Queue



INF=float('inf')



n=int(eval(input()))

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

for _ in range(n-1):

    u,v,w=list(map(int,input().split()))

    g[u-1].append((v-1,w))

    g[v-1].append((u-1,w))



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

ds=[INF]*n

ds[k-1]=0

que=Queue()

que.put((k-1,0))

while not que.empty():

    u,d=que.get()

    for v,w in g[u]:

        if ds[v]==INF:

            ds[v]=d+w

            que.put((v,d+w))



for _ in range(q):

    u,v=list(map(int,input().split()))

    print((ds[u-1]+ds[v-1]))

from collections import deque



INF=float('inf')



n=int(eval(input()))

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

for _ in range(n-1):

    u,v,w=list(map(int,input().split()))

    g[u-1].append((v-1,w))

    g[v-1].append((u-1,w))



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

ds=[INF]*n

ds[k-1]=0

que=deque()

que.append((k-1,0))

while len(que):

    u,d=que.popleft()

    for v,w in g[u]:

        if ds[v]==INF:

            ds[v]=d+w

            que.append((v,d+w))



for _ in range(q):

    u,v=list(map(int,input().split()))

    print((ds[u-1]+ds[v-1]))

from queue import Queue

INF = float("inf")
n = int(eval(input()))
g = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = list(map(int, input().split()))
    g[u - 1].append((v - 1, w))
    g[v - 1].append((u - 1, w))
q, k = list(map(int, input().split()))
ds = [INF] * n
ds[k - 1] = 0
que = Queue()
que.put((k - 1, 0))
while not que.empty():
    u, d = que.get()
    for v, w in g[u]:
        if ds[v] == INF:
            ds[v] = d + w
            que.put((v, d + w))
for _ in range(q):
    u, v = list(map(int, input().split()))
    print((ds[u - 1] + ds[v - 1]))

from collections import deque

INF = float("inf")
n = int(eval(input()))
g = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = list(map(int, input().split()))
    g[u - 1].append((v - 1, w))
    g[v - 1].append((u - 1, w))
q, k = list(map(int, input().split()))
ds = [INF] * n
ds[k - 1] = 0
que = deque()
que.append((k - 1, 0))
while len(que):
    u, d = que.popleft()
    for v, w in g[u]:
        if ds[v] == INF:
            ds[v] = d + w
            que.append((v, d + w))
for _ in range(q):
    u, v = list(map(int, input().split()))
    print((ds[u - 1] + ds[v - 1]))

-from queue import Queue +from collections import deque -que = Queue() -que.put((k - 1, 0)) -while not que.empty(): -    u, d = que.get() +que = deque() +que.append((k - 1, 0)) +while len(que): +    u, d = que.popleft() -            que.put((v, d + w)) +            que.append((v, d + w))