n = int(eval(input()))

tree = [[] for _ in range(n+1)]



for i in range(n-1):

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

    tree[a].append([b, c])

    tree[b].append([a, c])



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



from collections import deque

que = deque([k])

visit = [-1 for _ in range(n+1)]

visit[k] = 0

while que:

    pos = que.popleft()

    for i, j in tree[pos]:

        if visit[i] < 0:

            visit[i] = visit[pos]+j

            que.append(i)

for i in range(q):

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

    print((visit[x]+visit[y]))
def main():

    n = int(eval(input()))

    tree = [[] for _ in range(n+1)]



    for i in range(n-1):

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

        tree[a].append([b, c])

        tree[b].append([a, c])



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



    from collections import deque

    que = deque([k])

    visit = [-1 for _ in range(n+1)]

    visit[k] = 0

    while que:

        pos = que.popleft()

        for i, j in tree[pos]:

            if visit[i] < 0:

                visit[i] = visit[pos]+j

                que.append(i)

    for i in range(q):

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

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



if __name__=="__main__":

    main()
n = int(eval(input()))
tree = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    tree[a].append([b, c])
    tree[b].append([a, c])
q, k = list(map(int, input().split()))
from collections import deque

que = deque([k])
visit = [-1 for _ in range(n + 1)]
visit[k] = 0
while que:
    pos = que.popleft()
    for i, j in tree[pos]:
        if visit[i] < 0:
            visit[i] = visit[pos] + j
            que.append(i)
for i in range(q):
    x, y = list(map(int, input().split()))
    print((visit[x] + visit[y]))

def main():
    n = int(eval(input()))
    tree = [[] for _ in range(n + 1)]
    for i in range(n - 1):
        a, b, c = list(map(int, input().split()))
        tree[a].append([b, c])
        tree[b].append([a, c])
    q, k = list(map(int, input().split()))
    from collections import deque

    que = deque([k])
    visit = [-1 for _ in range(n + 1)]
    visit[k] = 0
    while que:
        pos = que.popleft()
        for i, j in tree[pos]:
            if visit[i] < 0:
                visit[i] = visit[pos] + j
                que.append(i)
    for i in range(q):
        x, y = list(map(int, input().split()))
        print((visit[x] + visit[y]))


if __name__ == "__main__":
    main()

-n = int(eval(input())) -tree = [[] for _ in range(n + 1)] -for i in range(n - 1): -    a, b, c = list(map(int, input().split())) -    tree[a].append([b, c]) -    tree[b].append([a, c]) -q, k = list(map(int, input().split())) -from collections import deque +def main(): +    n = int(eval(input())) +    tree = [[] for _ in range(n + 1)] +    for i in range(n - 1): +        a, b, c = list(map(int, input().split())) +        tree[a].append([b, c]) +        tree[b].append([a, c]) +    q, k = list(map(int, input().split())) +    from collections import deque -que = deque([k]) -visit = [-1 for _ in range(n + 1)] -visit[k] = 0 -while que: -    pos = que.popleft() -    for i, j in tree[pos]: -        if visit[i] < 0: -            visit[i] = visit[pos] + j -            que.append(i) -for i in range(q): -    x, y = list(map(int, input().split())) -    print((visit[x] + visit[y])) +    que = deque([k]) +    visit = [-1 for _ in range(n + 1)] +    visit[k] = 0 +    while que: +        pos = que.popleft() +        for i, j in tree[pos]: +            if visit[i] < 0: +                visit[i] = visit[pos] + j +                que.append(i) +    for i in range(q): +        x, y = list(map(int, input().split())) +        print((visit[x] + visit[y])) + + +if __name__ == "__main__": +    main()