import queue



N = int(eval(input()))

E = {n: set() for n in range(N)}



for _ in range(N - 1):

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

    a -= 1

    b -= 1

    E[a].add((b, c))

    E[b].add((a, c))



def m():

    Q, K = list(map(int, input().split()))

    K -= 1

    dist = [-1] * N

    already = set()

    que = queue.Queue()

    dist[K] = 0

    que.put(K)

    while not que.empty():

        now = que.get()

        out = E[now]

        for n, c in out:

            if dist[n] != -1:

                continue

            dist[n] = dist[now] + c        

            que.put(n)

    

    res = ""

    for _ in range(Q):

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

        x -= 1

        y -= 1

        res += str(dist[x] + dist[y]) + "\n"

    

    print(res)



if __name__ == "__main__":

    m()

import queue

import sys

input = sys.stdin.readline



N = int(eval(input()))

E = {n: set() for n in range(N)}



for _ in range(N - 1):

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

    a -= 1

    b -= 1

    E[a].add((b, c))

    E[b].add((a, c))



def m():

    Q, K = list(map(int, input().split()))

    K -= 1

    dist = [-1] * N

    already = set()

    que = queue.Queue()

    dist[K] = 0

    que.put(K)

    while not que.empty():

        now = que.get()

        out = E[now]

        for n, c in out:

            if dist[n] != -1:

                continue

            dist[n] = dist[now] + c        

            que.put(n)

    

    for _ in range(Q):

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

        x -= 1

        y -= 1

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



if __name__ == "__main__":

    m()

import queue

N = int(eval(input()))
E = {n: set() for n in range(N)}
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    E[a].add((b, c))
    E[b].add((a, c))


def m():
    Q, K = list(map(int, input().split()))
    K -= 1
    dist = [-1] * N
    already = set()
    que = queue.Queue()
    dist[K] = 0
    que.put(K)
    while not que.empty():
        now = que.get()
        out = E[now]
        for n, c in out:
            if dist[n] != -1:
                continue
            dist[n] = dist[now] + c
            que.put(n)
    res = ""
    for _ in range(Q):
        x, y = list(map(int, input().split()))
        x -= 1
        y -= 1
        res += str(dist[x] + dist[y]) + "\n"
    print(res)


if __name__ == "__main__":
    m()

import queue
import sys

input = sys.stdin.readline
N = int(eval(input()))
E = {n: set() for n in range(N)}
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    E[a].add((b, c))
    E[b].add((a, c))


def m():
    Q, K = list(map(int, input().split()))
    K -= 1
    dist = [-1] * N
    already = set()
    que = queue.Queue()
    dist[K] = 0
    que.put(K)
    while not que.empty():
        now = que.get()
        out = E[now]
        for n, c in out:
            if dist[n] != -1:
                continue
            dist[n] = dist[now] + c
            que.put(n)
    for _ in range(Q):
        x, y = list(map(int, input().split()))
        x -= 1
        y -= 1
        print((dist[x] + dist[y]))


if __name__ == "__main__":
    m()

+import sys +input = sys.stdin.readline -    res = "" -        res += str(dist[x] + dist[y]) + "\n" -    print(res) +        print((dist[x] + dist[y]))