# -*- coding: utf-8 -*-





def main():

    from collections import defaultdict

    from collections import deque



    n = int(eval(input()))

    graph = [defaultdict(int) for _ in range(n)]

    visited = [False for _ in range(n)]

    dist = [float('inf') for _ in range(n)]



    for i in range(n - 1):

        ai, bi, ci = list(map(int, input().split()))

        ai -= 1

        bi -= 1

        graph[ai][bi] = ci

        graph[bi][ai] = ci



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

    k -= 1

    dist[k] = 0

    d = deque()

    d.append(k)



    while d:

        di = d.popleft()

        visited[di] = True



        for bi, ci in list(graph[di].items()):

            if visited[bi]:

                continue



            dist[bi] = dist[di] + ci

            d.append(bi)



    ans = [0 for _ in range(q)]



    for j in range(q):

        xi, yi = list(map(int, input().split()))

        xi -= 1

        yi -= 1

        ans[j] = dist[xi] + dist[yi]



    print(('\n'.join(map(str, ans))))





if __name__ == '__main__':

    main()

# -*- coding: utf-8 -*-





def main():

    from collections import defaultdict

    from collections import deque

    import sys



    n = int(eval(input()))

    graph = [defaultdict(int) for _ in range(n)]

    visited = [False for _ in range(n)]

    dist = [float('inf') for _ in range(n)]

    lines = sys.stdin.readlines()



    for i in range(n - 1):

        ai, bi, ci = list(map(int, lines[i].split()))

        ai -= 1

        bi -= 1

        graph[ai][bi] = ci

        graph[bi][ai] = ci



    q, k = list(map(int, lines[n - 1].split()))

    k -= 1

    dist[k] = 0

    d = deque()

    d.append(k)



    while d:

        di = d.popleft()

        visited[di] = True



        for bi, ci in list(graph[di].items()):

            if visited[bi]:

                continue



            dist[bi] = dist[di] + ci

            d.append(bi)



    ans = [0 for _ in range(q)]



    for j in range(q):

        xi, yi = list(map(int, lines[n + j].split()))

        xi -= 1

        yi -= 1

        ans[j] = dist[xi] + dist[yi]



    print(('\n'.join(map(str, ans))))





if __name__ == '__main__':

    main()

# -*- coding: utf-8 -*-
def main():
    from collections import defaultdict
    from collections import deque

    n = int(eval(input()))
    graph = [defaultdict(int) for _ in range(n)]
    visited = [False for _ in range(n)]
    dist = [float("inf") for _ in range(n)]
    for i in range(n - 1):
        ai, bi, ci = list(map(int, input().split()))
        ai -= 1
        bi -= 1
        graph[ai][bi] = ci
        graph[bi][ai] = ci
    q, k = list(map(int, input().split()))
    k -= 1
    dist[k] = 0
    d = deque()
    d.append(k)
    while d:
        di = d.popleft()
        visited[di] = True
        for bi, ci in list(graph[di].items()):
            if visited[bi]:
                continue
            dist[bi] = dist[di] + ci
            d.append(bi)
    ans = [0 for _ in range(q)]
    for j in range(q):
        xi, yi = list(map(int, input().split()))
        xi -= 1
        yi -= 1
        ans[j] = dist[xi] + dist[yi]
    print(("\n".join(map(str, ans))))


if __name__ == "__main__":
    main()

# -*- coding: utf-8 -*-
def main():
    from collections import defaultdict
    from collections import deque
    import sys

    n = int(eval(input()))
    graph = [defaultdict(int) for _ in range(n)]
    visited = [False for _ in range(n)]
    dist = [float("inf") for _ in range(n)]
    lines = sys.stdin.readlines()
    for i in range(n - 1):
        ai, bi, ci = list(map(int, lines[i].split()))
        ai -= 1
        bi -= 1
        graph[ai][bi] = ci
        graph[bi][ai] = ci
    q, k = list(map(int, lines[n - 1].split()))
    k -= 1
    dist[k] = 0
    d = deque()
    d.append(k)
    while d:
        di = d.popleft()
        visited[di] = True
        for bi, ci in list(graph[di].items()):
            if visited[bi]:
                continue
            dist[bi] = dist[di] + ci
            d.append(bi)
    ans = [0 for _ in range(q)]
    for j in range(q):
        xi, yi = list(map(int, lines[n + j].split()))
        xi -= 1
        yi -= 1
        ans[j] = dist[xi] + dist[yi]
    print(("\n".join(map(str, ans))))


if __name__ == "__main__":
    main()

+    import sys +    lines = sys.stdin.readlines() -        ai, bi, ci = list(map(int, input().split())) +        ai, bi, ci = list(map(int, lines[i].split())) -    q, k = list(map(int, input().split())) +    q, k = list(map(int, lines[n - 1].split())) -        xi, yi = list(map(int, input().split())) +        xi, yi = list(map(int, lines[n + j].split()))