class RadixHeap:

    __slots__ = ["data", "last", "siz", "used"]



    # (max_key - min_key) <= C

    def __init__(self, N, C):

        self.data = [[] for i in range(C.bit_length() + 1000)]

        self.last = self.siz = 0

        self.used = [0] * N



    def push(self, x, key):

        # assert self.last <= x

        self.siz += 1

        self.data[(x ^ self.last).bit_length()].append((x, key))



    def pop(self):

        data = self.data

        used = self.used

        # assert self.siz > 0

        if not data[0]:

            i = 1

            while not data[i]:

                i += 1

            d = data[i]

            new_last, new_key = min(d)

            used[new_key] = 1

            for val in d:

                x, key = val

                if used[key]:

                    self.siz -= 1

                    continue

                data[(x ^ new_last).bit_length()].append(val)

            self.last = new_last

            data[i] = []

        else:

            new_last, new_key = data[0].pop()

            used[new_key] = 1

            self.siz -= 1

        return new_last, new_key



    def __len__(self):

        return self.siz



def dijkstra(N, G, s):

    que = RadixHeap(N, 10**9 + 1)



    dist = [10**18] * N

    dist[s] = 0

    que.push(0, s)

    while que:

        cost, v = que.pop()

        if dist[v] < cost:

            continue

        for w, c in G[v]:

            if cost + c < dist[w]:

                dist[w] = r = cost + c

                que.push(r, w)

    return dist



# ----------- #



n = int(eval(input()))

ABC = [tuple(int(x) for x in input().split()) for _ in range(n - 1)]

q, k = (int(x) for x in input().split())

queries = [tuple(int(x) for x in input().split()) for _ in range(q)]

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

for a, b, c in ABC:

    a -= 1

    b -= 1

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

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

dist = dijkstra(n, G, k-1)

for x, y in queries:

    x -= 1

    y -= 1

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

class Tree_with_edge_cost:

    def __init__(self, n, edge):

        self.n = n

        self.nexts = [[] for _ in range(n)]

        for u, v, c in edge:

            self.nexts[u].append((v, c))

            self.nexts[v].append((u, c))

        self.parent = [-1] * self.n

        self.children = [[] for _ in range(self.n)]

        self.cost = [0] * self.n

        self.dist = [0] * self.n  # 根からの距離

        self.depth = [0] * self.n  # 根からの深さ(cost=1での距離)

        self.order = []



    def set_root(self, root):  # O(n)

        self.order.append(root)

        stack = [root]

        while stack:

            v = stack.pop()

            for child, cost in self.nexts[v]:

                if child == self.parent[v]:

                    continue

                else:

                    self.parent[child] = v

                    self.children[v].append(child)

                    self.depth[child] = self.depth[v] + 1

                    self.dist[child] = self.dist[v] + cost

                    self.cost[child] = cost

                    self.order.append(child)

                    stack.append(child)



    def get_diameter(self, restore=False):  # double-sweepで求める  O(n)

        u = self.dist.index(max(self.dist))  # 根から一番遠いものを根とし、そこから一番遠いものを見つける

        dist_u = [-1] * self.n

        dist_u[u] = 0

        stack = [u]

        parent_u = [None for _ in range(self.n)]

        while stack:

            v = stack.pop()

            for child, cost in self.nexts[v]:

                if dist_u[child] == -1:

                    dist_u[child] = dist_u[v] + cost

                    parent_u[child] = v

                    stack.append(child)

        diameter = max(dist_u)

        v = dist_u.index(diameter)

        if restore:

            path = [v]

            while v != u:

                v = parent_u[v]

                path.append(v)

            path.reverse()  # [u,...,v]

            return diameter, path

        else:

            return diameter, u, v



# ---------------------- #



n = int(eval(input()))

edges = []

for _ in range(n-1):

    a, b, c = (int(x) for x in input().split())

    a -= 1

    b -= 1

    edges.append((a, b, c))

q, k = (int(x) for x in input().split())

queries = [tuple(int(x) for x in input().split()) for _ in range(q)]

tree = Tree_with_edge_cost(n, edges)

tree.set_root(k-1)



for x, y in queries:

    x -= 1

    y -= 1

    print((tree.dist[x] + tree.dist[y]))

class RadixHeap:
    __slots__ = ["data", "last", "siz", "used"]
    # (max_key - min_key) <= C
    def __init__(self, N, C):
        self.data = [[] for i in range(C.bit_length() + 1000)]
        self.last = self.siz = 0
        self.used = [0] * N

    def push(self, x, key):
        # assert self.last <= x
        self.siz += 1
        self.data[(x ^ self.last).bit_length()].append((x, key))

    def pop(self):
        data = self.data
        used = self.used
        # assert self.siz > 0
        if not data[0]:
            i = 1
            while not data[i]:
                i += 1
            d = data[i]
            new_last, new_key = min(d)
            used[new_key] = 1
            for val in d:
                x, key = val
                if used[key]:
                    self.siz -= 1
                    continue
                data[(x ^ new_last).bit_length()].append(val)
            self.last = new_last
            data[i] = []
        else:
            new_last, new_key = data[0].pop()
            used[new_key] = 1
            self.siz -= 1
        return new_last, new_key

    def __len__(self):
        return self.siz


def dijkstra(N, G, s):
    que = RadixHeap(N, 10**9 + 1)
    dist = [10**18] * N
    dist[s] = 0
    que.push(0, s)
    while que:
        cost, v = que.pop()
        if dist[v] < cost:
            continue
        for w, c in G[v]:
            if cost + c < dist[w]:
                dist[w] = r = cost + c
                que.push(r, w)
    return dist


# ----------- #
n = int(eval(input()))
ABC = [tuple(int(x) for x in input().split()) for _ in range(n - 1)]
q, k = (int(x) for x in input().split())
queries = [tuple(int(x) for x in input().split()) for _ in range(q)]
G = [[] for _ in range(n)]
for a, b, c in ABC:
    a -= 1
    b -= 1
    G[a].append((b, c))
    G[b].append((a, c))
dist = dijkstra(n, G, k - 1)
for x, y in queries:
    x -= 1
    y -= 1
    print((dist[x] + dist[y]))

class Tree_with_edge_cost:
    def __init__(self, n, edge):
        self.n = n
        self.nexts = [[] for _ in range(n)]
        for u, v, c in edge:
            self.nexts[u].append((v, c))
            self.nexts[v].append((u, c))
        self.parent = [-1] * self.n
        self.children = [[] for _ in range(self.n)]
        self.cost = [0] * self.n
        self.dist = [0] * self.n  # 根からの距離
        self.depth = [0] * self.n  # 根からの深さ(cost=1での距離)
        self.order = []

    def set_root(self, root):  # O(n)
        self.order.append(root)
        stack = [root]
        while stack:
            v = stack.pop()
            for child, cost in self.nexts[v]:
                if child == self.parent[v]:
                    continue
                else:
                    self.parent[child] = v
                    self.children[v].append(child)
                    self.depth[child] = self.depth[v] + 1
                    self.dist[child] = self.dist[v] + cost
                    self.cost[child] = cost
                    self.order.append(child)
                    stack.append(child)

    def get_diameter(self, restore=False):  # double-sweepで求める  O(n)
        u = self.dist.index(max(self.dist))  # 根から一番遠いものを根とし、そこから一番遠いものを見つける
        dist_u = [-1] * self.n
        dist_u[u] = 0
        stack = [u]
        parent_u = [None for _ in range(self.n)]
        while stack:
            v = stack.pop()
            for child, cost in self.nexts[v]:
                if dist_u[child] == -1:
                    dist_u[child] = dist_u[v] + cost
                    parent_u[child] = v
                    stack.append(child)
        diameter = max(dist_u)
        v = dist_u.index(diameter)
        if restore:
            path = [v]
            while v != u:
                v = parent_u[v]
                path.append(v)
            path.reverse()  # [u,...,v]
            return diameter, path
        else:
            return diameter, u, v


# ---------------------- #
n = int(eval(input()))
edges = []
for _ in range(n - 1):
    a, b, c = (int(x) for x in input().split())
    a -= 1
    b -= 1
    edges.append((a, b, c))
q, k = (int(x) for x in input().split())
queries = [tuple(int(x) for x in input().split()) for _ in range(q)]
tree = Tree_with_edge_cost(n, edges)
tree.set_root(k - 1)
for x, y in queries:
    x -= 1
    y -= 1
    print((tree.dist[x] + tree.dist[y]))

-class RadixHeap: -    __slots__ = ["data", "last", "siz", "used"] -    # (max_key - min_key) <= C -    def __init__(self, N, C): -        self.data = [[] for i in range(C.bit_length() + 1000)] -        self.last = self.siz = 0 -        self.used = [0] * N +class Tree_with_edge_cost: +    def __init__(self, n, edge): +        self.n = n +        self.nexts = [[] for _ in range(n)] +        for u, v, c in edge: +            self.nexts[u].append((v, c)) +            self.nexts[v].append((u, c)) +        self.parent = [-1] * self.n +        self.children = [[] for _ in range(self.n)] +        self.cost = [0] * self.n +        self.dist = [0] * self.n  # 根からの距離 +        self.depth = [0] * self.n  # 根からの深さ(cost=1での距離) +        self.order = [] -    def push(self, x, key): -        # assert self.last <= x -        self.siz += 1 -        self.data[(x ^ self.last).bit_length()].append((x, key)) +    def set_root(self, root):  # O(n) +        self.order.append(root) +        stack = [root] +        while stack: +            v = stack.pop() +            for child, cost in self.nexts[v]: +                if child == self.parent[v]: +                    continue +                else: +                    self.parent[child] = v +                    self.children[v].append(child) +                    self.depth[child] = self.depth[v] + 1 +                    self.dist[child] = self.dist[v] + cost +                    self.cost[child] = cost +                    self.order.append(child) +                    stack.append(child) -    def pop(self): -        data = self.data -        used = self.used -        # assert self.siz > 0 -        if not data[0]: -            i = 1 -            while not data[i]: -                i += 1 -            d = data[i] -            new_last, new_key = min(d) -            used[new_key] = 1 -            for val in d: -                x, key = val -                if used[key]: -                    self.siz -= 1 -                    continue -                data[(x ^ new_last).bit_length()].append(val) -            self.last = new_last -            data[i] = [] +    def get_diameter(self, restore=False):  # double-sweepで求める  O(n) +        u = self.dist.index(max(self.dist))  # 根から一番遠いものを根とし、そこから一番遠いものを見つける +        dist_u = [-1] * self.n +        dist_u[u] = 0 +        stack = [u] +        parent_u = [None for _ in range(self.n)] +        while stack: +            v = stack.pop() +            for child, cost in self.nexts[v]: +                if dist_u[child] == -1: +                    dist_u[child] = dist_u[v] + cost +                    parent_u[child] = v +                    stack.append(child) +        diameter = max(dist_u) +        v = dist_u.index(diameter) +        if restore: +            path = [v] +            while v != u: +                v = parent_u[v] +                path.append(v) +            path.reverse()  # [u,...,v] +            return diameter, path -            new_last, new_key = data[0].pop() -            used[new_key] = 1 -            self.siz -= 1 -        return new_last, new_key - -    def __len__(self): -        return self.siz +            return diameter, u, v -def dijkstra(N, G, s): -    que = RadixHeap(N, 10**9 + 1) -    dist = [10**18] * N -    dist[s] = 0 -    que.push(0, s) -    while que: -        cost, v = que.pop() -        if dist[v] < cost: -            continue -        for w, c in G[v]: -            if cost + c < dist[w]: -                dist[w] = r = cost + c -                que.push(r, w) -    return dist - - -ABC = [tuple(int(x) for x in input().split()) for _ in range(n - 1)] +edges = [] +for _ in range(n - 1): +    a, b, c = (int(x) for x in input().split()) +    a -= 1 +    b -= 1 +    edges.append((a, b, c)) -G = [[] for _ in range(n)] -for a, b, c in ABC: -    a -= 1 -    b -= 1 -    G[a].append((b, c)) -    G[b].append((a, c)) -dist = dijkstra(n, G, k - 1) +tree = Tree_with_edge_cost(n, edges) +tree.set_root(k - 1) -    print((dist[x] + dist[y])) +    print((tree.dist[x] + tree.dist[y]))