# Kから各頂点への距離をメモする

# xからKの距離とyからKの距離を足したものが答え



import sys

readline = sys.stdin.readline



N = int(readline())

G = [[] for i in range(N)]

for i in range(N - 1):

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

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

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



dist = [-1 for i in range(N)] # Kからの距離

Q,K = list(map(int,readline().split()))



dist[K - 1] = 0

from collections import deque

# 頂点、Kからの距離, 親

q = deque([[K - 1, 0, -1]])

while q:

  v, d, parent = q.popleft()

  dist[v] = d

  for child in G[v]:

    if child[0] == parent:

      continue

    q.append([child[0],d + child[1], v])



for i in range(Q):

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

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

  
import sys

readline = sys.stdin.readline



N = int(readline())

G = [[] for i in range(N)]



for i in range(N - 1):

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

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

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

  

Q,K = list(map(int,readline().split()))



dist = [0] * N

stack = [(K - 1, -1, 0)]

while stack:

  v,parent,cost = stack.pop()

  dist[v] = cost

  for child, c in G[v]:

    if child == parent:

      continue

    stack.append((child, v, cost + c))

    

for i in range(Q):

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

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

# Kから各頂点への距離をメモする
# xからKの距離とyからKの距離を足したものが答え
import sys

readline = sys.stdin.readline
N = int(readline())
G = [[] for i in range(N)]
for i in range(N - 1):
    a, b, c = list(map(int, readline().split()))
    G[a - 1].append((b - 1, c))
    G[b - 1].append((a - 1, c))
dist = [-1 for i in range(N)]  # Kからの距離
Q, K = list(map(int, readline().split()))
dist[K - 1] = 0
from collections import deque

# 頂点、Kからの距離, 親
q = deque([[K - 1, 0, -1]])
while q:
    v, d, parent = q.popleft()
    dist[v] = d
    for child in G[v]:
        if child[0] == parent:
            continue
        q.append([child[0], d + child[1], v])
for i in range(Q):
    x, y = list(map(int, readline().split()))
    print((dist[x - 1] + dist[y - 1]))

import sys

readline = sys.stdin.readline
N = int(readline())
G = [[] for i in range(N)]
for i in range(N - 1):
    a, b, c = list(map(int, readline().split()))
    G[a - 1].append((b - 1, c))
    G[b - 1].append((a - 1, c))
Q, K = list(map(int, readline().split()))
dist = [0] * N
stack = [(K - 1, -1, 0)]
while stack:
    v, parent, cost = stack.pop()
    dist[v] = cost
    for child, c in G[v]:
        if child == parent:
            continue
        stack.append((child, v, cost + c))
for i in range(Q):
    x, y = list(map(int, readline().split()))
    print((dist[x - 1] + dist[y - 1]))

-# Kから各頂点への距離をメモする -# xからKの距離とyからKの距離を足したものが答え -dist = [-1 for i in range(N)]  # Kからの距離 -dist[K - 1] = 0 -from collections import deque - -# 頂点、Kからの距離, 親 -q = deque([[K - 1, 0, -1]]) -while q: -    v, d, parent = q.popleft() -    dist[v] = d -    for child in G[v]: -        if child[0] == parent: +dist = [0] * N +stack = [(K - 1, -1, 0)] +while stack: +    v, parent, cost = stack.pop() +    dist[v] = cost +    for child, c in G[v]: +        if child == parent: -        q.append([child[0], d + child[1], v]) +        stack.append((child, v, cost + c))