CodeEff/ECCO huggingface dataset:
# Original solution
# bellman_fordは重いのでTLE

from collections import namedtuple
import sys

input = sys.stdin.readline


def solve():
    inf = 10 ** 14 + 10

    Edge = namedtuple('Edge', 'cost from_ to')

    def bellman_ford(s):
        # 始点sから各頂点への最短距離
        # O(VE) <- dijkstraならO(E log V)だが負辺は無理
        dist = [inf] * n
        dist[s] = 0

        while True:
            update = False
            for e_ in e:
                if dist[e_.from_] != inf and dist[e_.to] > dist[e_.from_] + e_.cost:
                    dist[e_.to] = dist[e_.from_] + e_.cost
                    update = True
            if not update:
                break
        return dist

    n = int(eval(input()))
    e = set()
    for _ in range(n - 1):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        e.add(Edge(cost=c, from_=a, to=b))
        e.add(Edge(cost=c, from_=b, to=a))

    q, v = list(map(int, input().split()))
    v -= 1

    d = bellman_ford(v)

    for _ in range(q):
        x, y = list(map(int, input().split()))
        x -= 1
        y -= 1
        print((d[x] + d[y]))


if __name__ == '__main__':
    solve()


# Optimized solution
# bellman_ford : O(V E)
# dijkstra : O(E log V), 負辺は無理
# warshall_floyd : O(V**3)

from collections import namedtuple
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline


def solve():
    inf = 10 ** 14 + 10

    Edge = namedtuple('Edge', 'cost to')

    def dfs(v: 'vertex_index, 0-indexed') -> None:
        for e_ in e[v]:
            if d[e_.to] != inf:
                continue
            d[e_.to] = d[v] + e_.cost
            dfs(e_.to)

    n = int(eval(input()))
    e = tuple(set() for _ in range(n))
    for _ in range(n - 1):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        e[a].add(Edge(cost=c, to=b))
        e[b].add(Edge(cost=c, to=a))

    q, v = list(map(int, input().split()))
    v -= 1

    d = [inf] * n
    d[v] = 0

    dfs(v)

    for _ in range(q):
        x, y = list(map(int, input().split()))
        x -= 1
        y -= 1
        print((d[x] + d[y]))


if __name__ == '__main__':
    solve()
# Original solution
# bellman_ford : O(V E)
# dijkstra : O(E log V), 負辺は無理
# warshall_floyd : O(V**3)

from collections import namedtuple
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline


def solve():
    inf = 10 ** 14 + 10

    Edge = namedtuple('Edge', 'cost to')

    def dfs(v: 'vertex_index, 0-indexed') -> None:
        for e_ in e[v]:
            if d[e_.to] != inf:
                continue
            d[e_.to] = d[v] + e_.cost
            dfs(e_.to)

    n = int(eval(input()))
    e = tuple(set() for _ in range(n))
    for _ in range(n - 1):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        e[a].add(Edge(cost=c, to=b))
        e[b].add(Edge(cost=c, to=a))

    q, v = list(map(int, input().split()))
    v -= 1

    d = [inf] * n
    d[v] = 0

    dfs(v)

    for _ in range(q):
        x, y = list(map(int, input().split()))
        x -= 1
        y -= 1
        print((d[x] + d[y]))


if __name__ == '__main__':
    solve()


# Optimized solution
# bellman_ford : O(V E)
# dijkstra : O(E log V), 負辺は無理
# warshall_floyd : O(V**3)

import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline


def solve():
    inf = 10 ** 14 + 10

    def dfs(v: 'vertex_index, 0-indexed') -> None:
        for c, t in e[v]:
            if d[t] != inf:
                continue
            d[t] = d[v] + c
            dfs(t)

    n = int(eval(input()))
    e = tuple(set() for _ in range(n))
    for _ in range(n - 1):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        e[a].add((c, b))
        e[b].add((c, a))

    q, v = list(map(int, input().split()))
    v -= 1

    d = [inf] * n
    d[v] = 0

    dfs(v)

    for _ in range(q):
        x, y = list(map(int, input().split()))
        x -= 1
        y -= 1
        print((d[x] + d[y]))


if __name__ == '__main__':
    solve()
# Original solution
def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d


N = int(eval(input()))

cost = [[float("inf") for i in range(N)] for i in range(N)]
for i in range(N-1):
    a, b, c = list(map(int, input().split()))
    cost[a-1][b-1] = c
    cost[b-1][a-1] = c

Q, K = list(map(int, input().split()))
    
ans = dijkstra(K-1, N, N-1, cost)
for i in range(Q):
    x, y = list(map(int, input().split()))
    print((ans[x-1] + ans[y-1]))

# Optimized solution
import sys
sys.setrecursionlimit(10**7)

N = int(eval(input()))
tree = [[] for _ in range(N)]
for i in range(N-1):
    a, b, c = list(map(int, input().split()))
    tree[a-1].append([b-1, c])
    tree[b-1].append([a-1, c])
Q, K = list(map(int, input().split()))

dist = [-1] * N
def dfs(v, total_cost):
    # v：頂点, total_cost：今までかかったコストの合計
    dist[v] = total_cost
    for v_next, cost in tree[v]:
        if dist[v_next] >= 0:
            continue
            # v_nextが訪問済みならスキップ
        dfs(v_next, total_cost+cost)

dfs(K-1, 0)

for i in range(Q):
    x, y = list(map(int, input().split()))
    print((dist[x-1] + dist[y-1]))
# Original solution
N = int(eval(input()))

edges = {}

for _ in range(N-1):
    a, b, c = list(map(int, input().split()))

    edges[(a, b)] = c
    edges[(b, a)] = c

Q, K = list(map(int, input().split()))
xy = []
for _ in range(Q):
    xy.append(tuple(map(int, input().split())))


d = [10**14] * (N+1)
d[K] = 0

for n in range(N):
    for e in edges:
        if d[e[0]] > d[e[1]] + edges[e]:
            d[e[0]] = d[e[1]] + edges[e]


for x, y in xy:
    print((d[x] + d[y]))


# Optimized solution
import sys
sys.setrecursionlimit(100005)

N = int(eval(input()))

edges = {n: [] for n in range(N+1)}

for _ in range(N-1):
    a, b, c = list(map(int, input().split()))

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

Q, K = list(map(int, input().split()))
xy = []
for _ in range(Q):
    xy.append(tuple(map(int, input().split())))


d = [-1] * (N+1)
d[K] = 0


def dfs(n: int):
    for m, c in edges[n]:
        if d[m] == -1:
            d[m] = d[n] + c
            dfs(m)


dfs(K)

for x, y in xy:
    print((d[x] + d[y]))
# Original solution
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""

#B
def dijkstra(k):
    d[k] = 0
    q = [[0,k]]
    while q:
        dx,x = heappop(q)
        for y,c in v[x]:
            if d[y] > dx+c:
                d[y] = dx+c
                heappush(q,[d[y],y])

n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a].append([b,c])
    v[b].append([a,c])
q,k = LI()
d = [float("inf") for i in range(n)]
dijkstra(k-1)
for i in range(q):
    x,y = LI()
    x -= 1
    y -= 1
    print((d[x]+d[y]))
#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""

#B
n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a].append([b,c])
    v[b].append([a,c])
Q,k = LI()
d = [-1 for i in range(n)]
d[k-1] = 0
q = deque()
q.append(k-1)
while q:
    x = q.pop()
    for y,c in v[x]:
        if d[y] == -1:
            d[y] = d[x]+c
            q.append(y)
for i in range(Q):
    x,y = LI()
    x -= 1
    y -= 1
    print((d[x]+d[y]))
#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T
# Original solution
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""

#B
n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a].append([b,c])
    v[b].append([a,c])
Q,k = LI()
d = [-1 for i in range(n)]
d[k-1] = 0
q = deque()
q.append(k-1)
while q:
    x = q.pop()
    for y,c in v[x]:
        if d[y] == -1:
            d[y] = d[x]+c
            q.append(y)
for i in range(Q):
    x,y = LI()
    x -= 1
    y -= 1
    print((d[x]+d[y]))
#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""

#B
n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a].append([b,c])
    v[b].append([a,c])
Q,k = LI()
d = [-1 for i in range(n)]
d[k-1] = 0
q = deque()
q.append(k-1)
while q:
    x = q.popleft()
    for y,c in v[x]:
        if d[y] == -1:
            d[y] = d[x]+c
            q.append(y)
for i in range(Q):
    x,y = LI()
    x -= 1
    y -= 1
    print((d[x]+d[y]))
#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T
# Original solution
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc070/editorial.pdf
・公式解が再帰だったのでやってみる
"""

import sys

# 再帰呼び出しの回数制限(デフォルト1000)
sys.setrecursionlimit(10 ** 9)

from heapq import heappop, heappush

N = int(eval(input()))
nodes = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b, c = list(map(int, input().split()))
    # nodes[出発ノード](到着ノード, コスト))
    nodes[a].append((b, c))
    # 無向グラフなのでこっちも入れる
    nodes[b].append((a, c))

memo = [0] * (N+1)
def dfs(cur, prev, dist):
    memo[cur] = dist
    for nxt, cost in nodes[cur]:
        if nxt == prev:
            continue
        dfs(nxt, cur, dist+cost)

Q, K = list(map(int, input().split()))
dfs(K, -1, 0)

for i in range(Q):
    x, y = list(map(int, input().split()))
    # 今回は全てKを経由するので、Kからの距離さえ分かれば全部出る
    print((memo[x] + memo[y]))


# Optimized solution
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc070/editorial.pdf
・公式解が再帰だったのでやってみる
"""

import sys

# 再帰呼び出しの回数制限(デフォルト1000)
sys.setrecursionlimit(10 ** 9)

N = int(eval(input()))
nodes = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b, c = list(map(int, input().split()))
    # nodes[出発ノード](到着ノード, コスト))
    nodes[a].append((b, c))
    # 無向グラフなのでこっちも入れる
    nodes[b].append((a, c))

memo = [0] * (N+1)
def dfs(cur, prev, dist):
    memo[cur] = dist
    for nxt, cost in nodes[cur]:
        if nxt == prev:
            continue
        dfs(nxt, cur, dist+cost)

Q, K = list(map(int, input().split()))
dfs(K, -1, 0)

for i in range(Q):
    x, y = list(map(int, input().split()))
    # 今回は全てKを経由するので、Kからの距離さえ分かれば全部出る
    print((memo[x] + memo[y]))
# Original solution
# -*- coding: utf-8 -*-

import sys
def input(): return sys.stdin.readline().strip()
    
from heapq import heappop, heappush

# 今回はダイクストラするので、データの持ち方は隣接リスト
N = int(eval(input()))
nodes = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b, c = list(map(int, input().split()))
    # nodes[出発ノード](到着ノード, コスト))
    nodes[a].append((b, c))
    # 無向グラフなのでこっちも入れる
    nodes[b].append((a, c))

def dijkstra(nodes, start):
    # 最短距離メモ
    memo = [float('inf')] * (len(nodes))
    # スタート位置
    que = [(0, start)]
    memo[start] = 0
    # キューが空になるまで
    while len(que) != 0:
        # startからの距離, 現在のノード
        dist, cur = heappop(que)
        # 出発ノードcurの到着ノードでループ
        for nxt, cost in nodes[cur]:
            # 今回の経路のが短い時
            if memo[cur] + cost < memo[nxt]:
                memo[nxt] = memo[cur] + cost
                # 現在の移動距離をキューの優先度として、早い方から先に処理するようにする
                heappush(que, (memo[nxt], nxt))
    # ノードstartからの最短距離リストを返却
    return memo

Q, K = list(map(int, input().split()))
# 引数：(ノードの隣接リスト, 出発ノード)
memo = dijkstra(nodes, K)

for i in range(Q):
    x, y = list(map(int, input().split()))
    # 今回は全てKを経由するので、Kからの距離さえ分かれば全部出る
    print((memo[x] + memo[y]))


# Optimized solution
# -*- coding: utf-8 -*-

import sys
def input(): return sys.stdin.readline().strip()

# 再帰呼び出しの回数制限(デフォルト1000)
sys.setrecursionlimit(10 ** 9)

N = int(eval(input()))
nodes = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b, c = list(map(int, input().split()))
    # nodes[出発ノード](到着ノード, コスト))
    nodes[a].append((b, c))
    # 無向グラフなのでこっちも入れる
    nodes[b].append((a, c))

memo = [0] * (N+1)
def dfs(cur, prev, dist):
    memo[cur] = dist
    for nxt, cost in nodes[cur]:
        if nxt == prev:
            continue
        dfs(nxt, cur, dist+cost)

Q, K = list(map(int, input().split()))
dfs(K, -1, 0)

for i in range(Q):
    x, y = list(map(int, input().split()))
    # 今回は全てKを経由するので、Kからの距離さえ分かれば全部出る
    print((memo[x] + memo[y]))
# Original solution
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def dijkstra(N: int, nodes: list, src: int) -> list:
    """ ダイクストラ高速化版(頂点数, 隣接リスト(0-indexed), 始点) """
    from heapq import heappush, heappop

    # 頂点[ある始点からの最短距離]
    res = [INF] * N
    # スタート位置
    que = [src]
    res[src] = 0
    # キューが空になるまで
    while len(que) != 0:
        # 距離*N + 現在のノード
        cur = heappop(que)
        # 距離とノードに分ける
        dist = cur // N
        cur %= N
        # 出発ノードcurの到着ノードでループ
        for nxt, cost in nodes[cur]:
            # 今回の経路のが短い時
            if dist + cost < res[nxt]:
                res[nxt] = dist + cost
                # 距離*N+ノード番号 の形でキューに詰める
                heappush(que, (dist+cost)*N+nxt)
    # ノードsrcからの最短距離リストを返却
    return res

N = INT()
nodes = [[] for i in range(N)]
for i in range(N-1):
    a, b, c = MAP()
    a -= 1; b -= 1
    nodes[a].append((b, c))
    nodes[b].append((a, c))

Q, K = MAP()
K -= 1
res = dijkstra(N, nodes, K)
for i in range(Q):
    x, y = MAP()
    x -= 1; y -= 1
    ans = res[x] + res[y]
    print(ans)


# Optimized solution
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def dfs(N, nodes, src):
    """ DFS(木、スタック、重みあり) """

    stack = [(src, -1, 0)]
    dist = [INF] * N
    while stack:
        u, prev, c1 = stack.pop()
        dist[u] = c1
        for v, c2 in nodes[u]:
            if v != prev:
                stack.append((v, u, c1+c2))
    return dist

N = INT()
nodes = [[] for i in range(N)]
for i in range(N-1):
    a, b, c = MAP()
    a -= 1; b -= 1
    nodes[a].append((b, c))
    nodes[b].append((a, c))

Q, K = MAP()
K -= 1
res = dfs(N, nodes, K)
for i in range(Q):
    x, y = MAP()
    x -= 1; y -= 1
    ans = res[x] + res[y]
    print(ans)
# Original solution
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def dfs(N, nodes, src):
    """ DFS(木、スタック、重みあり) """

    stack = [(src, -1, 0)]
    dist = [INF] * N
    while stack:
        u, prev, c1 = stack.pop()
        dist[u] = c1
        for v, c2 in nodes[u]:
            if v != prev:
                stack.append((v, u, c1+c2))
    return dist

N = INT()
nodes = [[] for i in range(N)]
for i in range(N-1):
    a, b, c = MAP()
    a -= 1; b -= 1
    nodes[a].append((b, c))
    nodes[b].append((a, c))

Q, K = MAP()
K -= 1
res = dfs(N, nodes, K)
for i in range(Q):
    x, y = MAP()
    x -= 1; y -= 1
    ans = res[x] + res[y]
    print(ans)


# Optimized solution
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def dfs(N, nodes, src):
    """ DFS(木、スタック、重みあり) """

    stack = [(src, -1, 0)]
    dist = [INF] * N
    while stack:
        u, prev, c1 = stack.pop()
        dist[u] = c1
        for v, c2 in nodes[u]:
            if v != prev:
                stack.append((v, u, c1+c2))
    return dist

N = INT()
nodes = [[] for i in range(N)]
for i in range(N-1):
    a, b, c = MAP()
    a -= 1; b -= 1
    nodes[a].append((b, c))
    nodes[b].append((a, c))

Q, K = MAP()
K -= 1
res = dfs(N, nodes, K)
ans = []
for i in range(Q):
    x, y = MAP()
    x -= 1; y -= 1
    ans.append(str(res[x] + res[y]))
print(('\n'.join(ans)))
# Original solution
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def dfs(N, nodes, src):
    """ DFS(木、スタック、重みあり) """

    stack = [(src, -1, 0)]
    dist = [INF] * N
    while stack:
        u, prev, c1 = stack.pop()
        dist[u] = c1
        for v, c2 in nodes[u]:
            if v != prev:
                stack.append((v, u, c1+c2))
    return dist

N = INT()
nodes = [[] for i in range(N)]
for i in range(N-1):
    a, b, c = MAP()
    a -= 1; b -= 1
    nodes[a].append((b, c))
    nodes[b].append((a, c))

Q, K = MAP()
K -= 1
res = dfs(N, nodes, K)
ans = []
for i in range(Q):
    x, y = MAP()
    x -= 1; y -= 1
    ans.append(str(res[x] + res[y]))
print(('\n'.join(ans)))


# Optimized solution
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def dfs(N, nodes, src):
    """ DFS(木、スタック、重みあり) """

    stack = [(src, -1, 0)]
    dist = [INF] * N
    while stack:
        u, prev, c1 = stack.pop()
        dist[u] = c1
        for v, c2 in nodes[u]:
            if v != prev:
                stack.append((v, u, c1+c2))
    return dist

N = INT()
nodes = [[] for i in range(N)]
for i in range(N-1):
    a, b, c = MAP()
    a -= 1; b -= 1
    nodes[a].append((b, c))
    nodes[b].append((a, c))

Q, K = MAP()
K -= 1
res = dfs(N, nodes, K)
for i in range(Q):
    x, y = MAP()
    x -= 1; y -= 1
    ans = res[x] + res[y]
    print(ans)