import sys

sys.setrecursionlimit(10 ** 6)





class Tree:

    WHITE = 0

    GRAY = -1

    BLACK = 1



    def __init__(self, adj):

        n = len(adj)

        self.adj = adj

        self.colors = [self.WHITE] * n

        self.depths = [-1] * n

        self.depth = 0



    def init(self):

        self.__init__(self.adj)



    def dfs(self, u):

        if self.colors[u] == self.BLACK:

            return



        self.colors[u] = self.GRAY

        self.depths[u] = self.depth



        for v, w in self.adj[u]:

            if self.colors[v] == self.WHITE:

                self.depth += w

                self.dfs(v)

                self.depth -= w



        self.colors[u] = self.BLACK





n = int(eval(input()))

abc = [list(map(int, input().split())) for _ in range(n - 1)]

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

xy = [list(map(int, input().split())) for _ in range(q)]



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

for a, b, c in abc:

	a -= 1

	b -= 1

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

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



tree = Tree(adj)

tree.dfs(k-1)



for x, y in xy:

	x -= 1

	y -= 1

	ans = tree.depths[x] + tree.depths[y]

	print(ans)

n = int(eval(input()))

abc = [list(map(int, input().split())) for _ in range(n - 1)]

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

xy = [list(map(int, input().split())) for _ in range(q)]



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

for a, b, c in abc:

	a -= 1

	b -= 1

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

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





def dfs(s):

	d = [-1] * n

	d[s] = 0

	stack = [s]



	while stack:

		u = stack.pop()

		for v, c in adj[u]:

			if d[v] == -1:

				d[v] = d[u] + c

				stack.append(v)



	return d





depths = dfs(k-1)



for x, y in xy:

	x -= 1

	y -= 1

	ans = depths[x] + depths[y]

	print(ans)

import sys

sys.setrecursionlimit(10**6)


class Tree:
    WHITE = 0
    GRAY = -1
    BLACK = 1

    def __init__(self, adj):
        n = len(adj)
        self.adj = adj
        self.colors = [self.WHITE] * n
        self.depths = [-1] * n
        self.depth = 0

    def init(self):
        self.__init__(self.adj)

    def dfs(self, u):
        if self.colors[u] == self.BLACK:
            return
        self.colors[u] = self.GRAY
        self.depths[u] = self.depth
        for v, w in self.adj[u]:
            if self.colors[v] == self.WHITE:
                self.depth += w
                self.dfs(v)
                self.depth -= w
        self.colors[u] = self.BLACK


n = int(eval(input()))
abc = [list(map(int, input().split())) for _ in range(n - 1)]
q, k = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(q)]
adj = [[] for _ in range(n)]
for a, b, c in abc:
    a -= 1
    b -= 1
    adj[a].append([b, c])
    adj[b].append([a, c])
tree = Tree(adj)
tree.dfs(k - 1)
for x, y in xy:
    x -= 1
    y -= 1
    ans = tree.depths[x] + tree.depths[y]
    print(ans)

n = int(eval(input()))
abc = [list(map(int, input().split())) for _ in range(n - 1)]
q, k = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(q)]
adj = [[] for _ in range(n)]
for a, b, c in abc:
    a -= 1
    b -= 1
    adj[a].append([b, c])
    adj[b].append([a, c])


def dfs(s):
    d = [-1] * n
    d[s] = 0
    stack = [s]
    while stack:
        u = stack.pop()
        for v, c in adj[u]:
            if d[v] == -1:
                d[v] = d[u] + c
                stack.append(v)
    return d


depths = dfs(k - 1)
for x, y in xy:
    x -= 1
    y -= 1
    ans = depths[x] + depths[y]
    print(ans)

-import sys - -sys.setrecursionlimit(10**6) - - -class Tree: -    WHITE = 0 -    GRAY = -1 -    BLACK = 1 - -    def __init__(self, adj): -        n = len(adj) -        self.adj = adj -        self.colors = [self.WHITE] * n -        self.depths = [-1] * n -        self.depth = 0 - -    def init(self): -        self.__init__(self.adj) - -    def dfs(self, u): -        if self.colors[u] == self.BLACK: -            return -        self.colors[u] = self.GRAY -        self.depths[u] = self.depth -        for v, w in self.adj[u]: -            if self.colors[v] == self.WHITE: -                self.depth += w -                self.dfs(v) -                self.depth -= w -        self.colors[u] = self.BLACK - - -tree = Tree(adj) -tree.dfs(k - 1) + + +def dfs(s): +    d = [-1] * n +    d[s] = 0 +    stack = [s] +    while stack: +        u = stack.pop() +        for v, c in adj[u]: +            if d[v] == -1: +                d[v] = d[u] + c +                stack.append(v) +    return d + + +depths = dfs(k - 1) -    ans = tree.depths[x] + tree.depths[y] +    ans = depths[x] + depths[y]