import sys

from collections import defaultdict as dd

input = sys.stdin.readline

N = int(eval(input()))

e = dd(list)

for _ in range(N - 1):

  u, v, c = list(map(int, input().split()))

  e[u].append((v, c))

  e[v].append((u, c))

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

import heapq

class dijkstra:

  def __init__(self, n, e):

    self.e = e

    self.n = n

  def path(self, s, t):

    d = [float("inf")] * (self.n + 1)

    vis = set()

    d[s] = 0

    h = [s]

    while not t in vis and len(h):

      v = heapq.heappop(h)

      v1 = v % (10 ** 6)

      v0 = v // (10 ** 6)

      if v1 in vis: continue

      vis.add(v1)

      for p in self.e[v1]:

        d[p[0]] = min(d[p[0]], d[v1] + p[1])

        if p[0] in vis: continue

        heapq.heappush(h, d[p[0]] * (10 ** 6) + p[0])

    return d

dij = dijkstra(N, e)

p = dij.path(K, 0)



for _ in range(Q):

  u, v = list(map(int, input().split()))

  print((p[u] + p[v]))
import sys

from collections import defaultdict as dd

input = sys.stdin.readline

N = int(eval(input()))

e = dd(list)

for _ in range(N - 1):

  u, v, c = list(map(int, input().split()))

  e[u].append((v, c))

  e[v].append((u, c))

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



dp = [10 ** 15] * (N + 1)

dp[K] = 0

s = [K]

while len(s):

  x = s.pop()

  for y, d in e[x]:

    if dp[y] > dp[x] + d:

      s.append(y)

      dp[y] = dp[x] + d



for _ in range(Q):

  u, v = list(map(int, input().split()))

  print((dp[u] + dp[v]))
import sys
from collections import defaultdict as dd

input = sys.stdin.readline
N = int(eval(input()))
e = dd(list)
for _ in range(N - 1):
    u, v, c = list(map(int, input().split()))
    e[u].append((v, c))
    e[v].append((u, c))
Q, K = list(map(int, input().split()))
import heapq


class dijkstra:
    def __init__(self, n, e):
        self.e = e
        self.n = n

    def path(self, s, t):
        d = [float("inf")] * (self.n + 1)
        vis = set()
        d[s] = 0
        h = [s]
        while not t in vis and len(h):
            v = heapq.heappop(h)
            v1 = v % (10**6)
            v0 = v // (10**6)
            if v1 in vis:
                continue
            vis.add(v1)
            for p in self.e[v1]:
                d[p[0]] = min(d[p[0]], d[v1] + p[1])
                if p[0] in vis:
                    continue
                heapq.heappush(h, d[p[0]] * (10**6) + p[0])
        return d


dij = dijkstra(N, e)
p = dij.path(K, 0)
for _ in range(Q):
    u, v = list(map(int, input().split()))
    print((p[u] + p[v]))

import sys
from collections import defaultdict as dd

input = sys.stdin.readline
N = int(eval(input()))
e = dd(list)
for _ in range(N - 1):
    u, v, c = list(map(int, input().split()))
    e[u].append((v, c))
    e[v].append((u, c))
Q, K = list(map(int, input().split()))
dp = [10**15] * (N + 1)
dp[K] = 0
s = [K]
while len(s):
    x = s.pop()
    for y, d in e[x]:
        if dp[y] > dp[x] + d:
            s.append(y)
            dp[y] = dp[x] + d
for _ in range(Q):
    u, v = list(map(int, input().split()))
    print((dp[u] + dp[v]))

-import heapq - - -class dijkstra: -    def __init__(self, n, e): -        self.e = e -        self.n = n - -    def path(self, s, t): -        d = [float("inf")] * (self.n + 1) -        vis = set() -        d[s] = 0 -        h = [s] -        while not t in vis and len(h): -            v = heapq.heappop(h) -            v1 = v % (10**6) -            v0 = v // (10**6) -            if v1 in vis: -                continue -            vis.add(v1) -            for p in self.e[v1]: -                d[p[0]] = min(d[p[0]], d[v1] + p[1]) -                if p[0] in vis: -                    continue -                heapq.heappush(h, d[p[0]] * (10**6) + p[0]) -        return d - - -dij = dijkstra(N, e) -p = dij.path(K, 0) +dp = [10**15] * (N + 1) +dp[K] = 0 +s = [K] +while len(s): +    x = s.pop() +    for y, d in e[x]: +        if dp[y] > dp[x] + d: +            s.append(y) +            dp[y] = dp[x] + d -    print((p[u] + p[v])) +    print((dp[u] + dp[v]))