# bellman_ford : O(V E)

# dijkstra : O(E log V), 負辺は無理

# warshall_floyd : O(V**3)



from collections import namedtuple

import sys



sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline





def solve():

    inf = 10 ** 14 + 10



    Edge = namedtuple('Edge', 'cost to')



    def dfs(v: 'vertex_index, 0-indexed') -> None:

        for e_ in e[v]:

            if d[e_.to] != inf:

                continue

            d[e_.to] = d[v] + e_.cost

            dfs(e_.to)



    n = int(eval(input()))

    e = tuple(set() for _ in range(n))

    for _ in range(n - 1):

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

        a -= 1

        b -= 1

        e[a].add(Edge(cost=c, to=b))

        e[b].add(Edge(cost=c, to=a))



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

    v -= 1



    d = [inf] * n

    d[v] = 0



    dfs(v)



    for _ in range(q):

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

        x -= 1

        y -= 1

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





if __name__ == '__main__':

    solve()

# bellman_ford : O(V E)

# dijkstra : O(E log V), 負辺は無理

# warshall_floyd : O(V**3)



import sys



sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline





def solve():

    inf = 10 ** 14 + 10



    def dfs(v: 'vertex_index, 0-indexed') -> None:

        for c, t in e[v]:

            if d[t] != inf:

                continue

            d[t] = d[v] + c

            dfs(t)



    n = int(eval(input()))

    e = tuple(set() for _ in range(n))

    for _ in range(n - 1):

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

        a -= 1

        b -= 1

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

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



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

    v -= 1



    d = [inf] * n

    d[v] = 0



    dfs(v)



    for _ in range(q):

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

        x -= 1

        y -= 1

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





if __name__ == '__main__':

    solve()

# bellman_ford : O(V E)
# dijkstra : O(E log V), 負辺は無理
# warshall_floyd : O(V**3)
from collections import namedtuple
import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline


def solve():
    inf = 10**14 + 10
    Edge = namedtuple("Edge", "cost to")

    def dfs(v: "vertex_index, 0-indexed") -> None:
        for e_ in e[v]:
            if d[e_.to] != inf:
                continue
            d[e_.to] = d[v] + e_.cost
            dfs(e_.to)

    n = int(eval(input()))
    e = tuple(set() for _ in range(n))
    for _ in range(n - 1):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        e[a].add(Edge(cost=c, to=b))
        e[b].add(Edge(cost=c, to=a))
    q, v = list(map(int, input().split()))
    v -= 1
    d = [inf] * n
    d[v] = 0
    dfs(v)
    for _ in range(q):
        x, y = list(map(int, input().split()))
        x -= 1
        y -= 1
        print((d[x] + d[y]))


if __name__ == "__main__":
    solve()

# bellman_ford : O(V E)
# dijkstra : O(E log V), 負辺は無理
# warshall_floyd : O(V**3)
import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline


def solve():
    inf = 10**14 + 10

    def dfs(v: "vertex_index, 0-indexed") -> None:
        for c, t in e[v]:
            if d[t] != inf:
                continue
            d[t] = d[v] + c
            dfs(t)

    n = int(eval(input()))
    e = tuple(set() for _ in range(n))
    for _ in range(n - 1):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        e[a].add((c, b))
        e[b].add((c, a))
    q, v = list(map(int, input().split()))
    v -= 1
    d = [inf] * n
    d[v] = 0
    dfs(v)
    for _ in range(q):
        x, y = list(map(int, input().split()))
        x -= 1
        y -= 1
        print((d[x] + d[y]))


if __name__ == "__main__":
    solve()

-from collections import namedtuple -    Edge = namedtuple("Edge", "cost to") -        for e_ in e[v]: -            if d[e_.to] != inf: +        for c, t in e[v]: +            if d[t] != inf: -            d[e_.to] = d[v] + e_.cost -            dfs(e_.to) +            d[t] = d[v] + c +            dfs(t) -        e[a].add(Edge(cost=c, to=b)) -        e[b].add(Edge(cost=c, to=a)) +        e[a].add((c, b)) +        e[b].add((c, a))