import sys

import collections





def solve():

    input = sys.stdin.readline

    mod = 10 ** 9 + 7

    n = int(input().rstrip('\n'))

    tmd = collections.defaultdict(list)

    tmdc = collections.defaultdict(int)

    for i in range(n-1):

        tma, tmb, tmc = list(map(int, input().rstrip('\n').split()))

        tmd[tma-1] += [tmb-1]

        tmd[tmb-1] += [tma-1]

        tmdc[tma-1, tmb-1] = tmc

        tmdc[tmb-1, tma-1] = tmc



    q, k = list(map(int, input().rstrip('\n').split()))

    ql = [[0, k-1]]

    ql = collections.deque(ql)

    fq = collections.defaultdict(int)

    fq[k-1]

    while True:

        if len(ql) != 0:

            cost, tmp = ql.popleft()

            for tmv in tmd[tmp]:

                if tmv not in fq or cost + tmdc[tmp, tmv] < fq[tmv]:

                    ql.append([cost + tmdc[tmp, tmv], tmv])

                    fq[tmv] = cost + tmdc[tmp, tmv]

        else:

            break

    for i in range(q):

        x, y = list(map(int, input().rstrip('\n').split()))

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





if __name__ == '__main__':

    solve()

import sys

import collections





def solve():

    readline = sys.stdin.buffer.readline

    mod = 10 ** 9 + 7

    n = int(readline())

    tmd = collections.defaultdict(list)

    cl = collections.defaultdict(int)

    for i in range(n-1):

        tma, tmb, tmc = list(map(int, readline().split()))

        tmd[tma-1] += [tmb-1]

        tmd[tmb-1] += [tma-1]

        cl[tma-1, tmb-1] = tmc

        cl[tmb-1, tma-1] = tmc

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



    ql = [[0, k-1]]

    ql = collections.deque(ql)

    fq = collections.defaultdict(int)

    fq[k-1]

    while True:

        if len(ql) != 0:

            cost, tmp = ql.popleft()

            for tmv in tmd[tmp]:

                if tmv not in fq:

                    ql.append([cost + cl[tmv, tmp], tmv])

                    fq[tmv] = cost + cl[tmv, tmp]

                elif cost + cl[tmv, tmp] < fq[tmv]:

                    fq[tmv] = cost + cl[tmv, tmp]

        else:

            break

    for i in range(q):

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

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





if __name__ == '__main__':

    solve()

import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10**9 + 7
    n = int(input().rstrip("\n"))
    tmd = collections.defaultdict(list)
    tmdc = collections.defaultdict(int)
    for i in range(n - 1):
        tma, tmb, tmc = list(map(int, input().rstrip("\n").split()))
        tmd[tma - 1] += [tmb - 1]
        tmd[tmb - 1] += [tma - 1]
        tmdc[tma - 1, tmb - 1] = tmc
        tmdc[tmb - 1, tma - 1] = tmc
    q, k = list(map(int, input().rstrip("\n").split()))
    ql = [[0, k - 1]]
    ql = collections.deque(ql)
    fq = collections.defaultdict(int)
    fq[k - 1]
    while True:
        if len(ql) != 0:
            cost, tmp = ql.popleft()
            for tmv in tmd[tmp]:
                if tmv not in fq or cost + tmdc[tmp, tmv] < fq[tmv]:
                    ql.append([cost + tmdc[tmp, tmv], tmv])
                    fq[tmv] = cost + tmdc[tmp, tmv]
        else:
            break
    for i in range(q):
        x, y = list(map(int, input().rstrip("\n").split()))
        print((fq[x - 1] + fq[y - 1]))


if __name__ == "__main__":
    solve()

import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10**9 + 7
    n = int(readline())
    tmd = collections.defaultdict(list)
    cl = collections.defaultdict(int)
    for i in range(n - 1):
        tma, tmb, tmc = list(map(int, readline().split()))
        tmd[tma - 1] += [tmb - 1]
        tmd[tmb - 1] += [tma - 1]
        cl[tma - 1, tmb - 1] = tmc
        cl[tmb - 1, tma - 1] = tmc
    q, k = list(map(int, readline().split()))
    ql = [[0, k - 1]]
    ql = collections.deque(ql)
    fq = collections.defaultdict(int)
    fq[k - 1]
    while True:
        if len(ql) != 0:
            cost, tmp = ql.popleft()
            for tmv in tmd[tmp]:
                if tmv not in fq:
                    ql.append([cost + cl[tmv, tmp], tmv])
                    fq[tmv] = cost + cl[tmv, tmp]
                elif cost + cl[tmv, tmp] < fq[tmv]:
                    fq[tmv] = cost + cl[tmv, tmp]
        else:
            break
    for i in range(q):
        x, y = list(map(int, readline().split()))
        print((fq[x - 1] + fq[y - 1]))


if __name__ == "__main__":
    solve()

-    input = sys.stdin.readline +    readline = sys.stdin.buffer.readline -    n = int(input().rstrip("\n")) +    n = int(readline()) -    tmdc = collections.defaultdict(int) +    cl = collections.defaultdict(int) -        tma, tmb, tmc = list(map(int, input().rstrip("\n").split())) +        tma, tmb, tmc = list(map(int, readline().split())) -        tmdc[tma - 1, tmb - 1] = tmc -        tmdc[tmb - 1, tma - 1] = tmc -    q, k = list(map(int, input().rstrip("\n").split())) +        cl[tma - 1, tmb - 1] = tmc +        cl[tmb - 1, tma - 1] = tmc +    q, k = list(map(int, readline().split())) -                if tmv not in fq or cost + tmdc[tmp, tmv] < fq[tmv]: -                    ql.append([cost + tmdc[tmp, tmv], tmv]) -                    fq[tmv] = cost + tmdc[tmp, tmv] +                if tmv not in fq: +                    ql.append([cost + cl[tmv, tmp], tmv]) +                    fq[tmv] = cost + cl[tmv, tmp] +                elif cost + cl[tmv, tmp] < fq[tmv]: +                    fq[tmv] = cost + cl[tmv, tmp] -        x, y = list(map(int, input().rstrip("\n").split())) +        x, y = list(map(int, readline().split()))