import sys

input = sys.stdin.readline

sys.setrecursionlimit(1000000)

from collections import deque

def getN():

    return int(eval(input()))

def getList():

    return list(map(int, input().split()))

import math



n = getN()



vtxs = [[] for i in range(n)]

dist = [0 for i in range(n)]

visit = [0 for i in range(n)]



for i in range(n-1):

    a,b,c = getList()

    vtxs[a-1].append((b-1 ,c))

    vtxs[b-1].append((a-1 ,c))



ques, k = getList()



from collections import deque

q = deque([k-1])

visit[k-1] = 1

while(q):

    cur = q.popleft()

    cdist = dist[cur]

    for nx in vtxs[cur]:

        nxa, nxc = nx

        if visit[nxa] == 0:

            dist[nxa] = cdist + nxc

            visit[nxa] = 1

            q.append(nxa)



for i in range(ques):

    x, y = getList()

    print((dist[x-1] + dist[y-1]))
import sys

# from collections import defaultdict, deque

import math

# import copy

# from bisect import bisect_left, bisect_right

import heapq



# sys.setrecursionlimit(1000000)



# input aliases

input = sys.stdin.readline



getS = lambda: input().strip()

getN = lambda: int(eval(input()))

getList = lambda: list(map(int, input().split()))

getZList = lambda: [int(x) - 1 for x in input().split()]



INF = 10 ** 20

MOD = 1000000007





def dijkstra(graph, start, n):

    h = []

    heapq.heappush(h, (0, start))

    costs = [INF for _ in range(n)]

    while h:

        cost, cur = heapq.heappop(h)

        if costs[cur] != INF:

            continue

        costs[cur] = cost

        for edge in graph[cur]:

            ecost, tgt = edge

            if costs[tgt] == INF:

                heapq.heappush(h, (cost + ecost, tgt))



    return costs



def solve():

    n = getN()

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

    for i in range(n-1):

        a,b,c = getList()

        a,b = a-1, b-1



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

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

    q, k = getList()

    costs = dijkstra(graph, k-1, n)

    # print(costs)

    for i in range(q):

        s, e = getZList()



        print((costs[s] + costs[e]))



    return



def main():

    n = getN()

    for _ in range(n):

        solve()

if __name__ == "__main__":

    # main()

    solve()

import sys

input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque


def getN():
    return int(eval(input()))


def getList():
    return list(map(int, input().split()))


import math

n = getN()
vtxs = [[] for i in range(n)]
dist = [0 for i in range(n)]
visit = [0 for i in range(n)]
for i in range(n - 1):
    a, b, c = getList()
    vtxs[a - 1].append((b - 1, c))
    vtxs[b - 1].append((a - 1, c))
ques, k = getList()
from collections import deque

q = deque([k - 1])
visit[k - 1] = 1
while q:
    cur = q.popleft()
    cdist = dist[cur]
    for nx in vtxs[cur]:
        nxa, nxc = nx
        if visit[nxa] == 0:
            dist[nxa] = cdist + nxc
            visit[nxa] = 1
            q.append(nxa)
for i in range(ques):
    x, y = getList()
    print((dist[x - 1] + dist[y - 1]))

import sys

# from collections import defaultdict, deque
import math

# import copy
# from bisect import bisect_left, bisect_right
import heapq

# sys.setrecursionlimit(1000000)
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(eval(input()))
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
INF = 10**20
MOD = 1000000007


def dijkstra(graph, start, n):
    h = []
    heapq.heappush(h, (0, start))
    costs = [INF for _ in range(n)]
    while h:
        cost, cur = heapq.heappop(h)
        if costs[cur] != INF:
            continue
        costs[cur] = cost
        for edge in graph[cur]:
            ecost, tgt = edge
            if costs[tgt] == INF:
                heapq.heappush(h, (cost + ecost, tgt))
    return costs


def solve():
    n = getN()
    graph = [[] for _ in range(n)]
    for i in range(n - 1):
        a, b, c = getList()
        a, b = a - 1, b - 1
        graph[a].append([c, b])
        graph[b].append([c, a])
    q, k = getList()
    costs = dijkstra(graph, k - 1, n)
    # print(costs)
    for i in range(q):
        s, e = getZList()
        print((costs[s] + costs[e]))
    return


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

+# from collections import defaultdict, deque +import math + +# import copy +# from bisect import bisect_left, bisect_right +import heapq + +# sys.setrecursionlimit(1000000) +# input aliases -sys.setrecursionlimit(1000000) -from collections import deque +getS = lambda: input().strip() +getN = lambda: int(eval(input())) +getList = lambda: list(map(int, input().split())) +getZList = lambda: [int(x) - 1 for x in input().split()] +INF = 10**20 +MOD = 1000000007 -def getN(): -    return int(eval(input())) +def dijkstra(graph, start, n): +    h = [] +    heapq.heappush(h, (0, start)) +    costs = [INF for _ in range(n)] +    while h: +        cost, cur = heapq.heappop(h) +        if costs[cur] != INF: +            continue +        costs[cur] = cost +        for edge in graph[cur]: +            ecost, tgt = edge +            if costs[tgt] == INF: +                heapq.heappush(h, (cost + ecost, tgt)) +    return costs -def getList(): -    return list(map(int, input().split())) +def solve(): +    n = getN() +    graph = [[] for _ in range(n)] +    for i in range(n - 1): +        a, b, c = getList() +        a, b = a - 1, b - 1 +        graph[a].append([c, b]) +        graph[b].append([c, a]) +    q, k = getList() +    costs = dijkstra(graph, k - 1, n) +    # print(costs) +    for i in range(q): +        s, e = getZList() +        print((costs[s] + costs[e])) +    return -import math +def main(): +    n = getN() +    for _ in range(n): +        solve() -n = getN() -vtxs = [[] for i in range(n)] -dist = [0 for i in range(n)] -visit = [0 for i in range(n)] -for i in range(n - 1): -    a, b, c = getList() -    vtxs[a - 1].append((b - 1, c)) -    vtxs[b - 1].append((a - 1, c)) -ques, k = getList() -from collections import deque -q = deque([k - 1]) -visit[k - 1] = 1 -while q: -    cur = q.popleft() -    cdist = dist[cur] -    for nx in vtxs[cur]: -        nxa, nxc = nx -        if visit[nxa] == 0: -            dist[nxa] = cdist + nxc -            visit[nxa] = 1 -            q.append(nxa) -for i in range(ques): -    x, y = getList() -    print((dist[x - 1] + dist[y - 1])) +if __name__ == "__main__": +    # main() +    solve()