import sys

input = sys.stdin.readline



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)]



G = [[] * N for _ in range(N)]

for a, b, c in ABC:

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

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



D = [-1] * N

s = [(K - 1, 0)]

while s:

  v, c = s.pop()

  D[v] = c

  for vv, cc in G[v]:

    if D[vv] < 0:

      s.append((vv, cc + c))

  

for x, y in XY:

  print((D[x - 1] + D[y - 1]))
import sys

input = sys.stdin.readline



N = int(eval(input()))



G = [[] * N for _ in range(N)]

for _ in range(N - 1):

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

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

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



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



D = [-1] * N

s = [(K - 1, 0)]

while s:

  v, c = s.pop()

  D[v] = c

  for vv, cc in G[v]:

    if D[vv] < 0:

      s.append((vv, cc + c))



for _ in range(Q):

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

  print((D[x - 1] + D[y - 1]))
import sys

input = sys.stdin.readline
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)]
G = [[] * N for _ in range(N)]
for a, b, c in ABC:
    G[a - 1].append((b - 1, c))
    G[b - 1].append((a - 1, c))
D = [-1] * N
s = [(K - 1, 0)]
while s:
    v, c = s.pop()
    D[v] = c
    for vv, cc in G[v]:
        if D[vv] < 0:
            s.append((vv, cc + c))
for x, y in XY:
    print((D[x - 1] + D[y - 1]))

import sys

input = sys.stdin.readline
N = int(eval(input()))
G = [[] * N for _ in range(N)]
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    G[a - 1].append((b - 1, c))
    G[b - 1].append((a - 1, c))
Q, K = list(map(int, input().split()))
D = [-1] * N
s = [(K - 1, 0)]
while s:
    v, c = s.pop()
    D[v] = c
    for vv, cc in G[v]:
        if D[vv] < 0:
            s.append((vv, cc + c))
for _ in range(Q):
    x, y = list(map(int, input().split()))
    print((D[x - 1] + D[y - 1]))

-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)] -for a, b, c in ABC: +for _ in range(N - 1): +    a, b, c = list(map(int, input().split())) +Q, K = list(map(int, input().split())) -for x, y in XY: +for _ in range(Q): +    x, y = list(map(int, input().split()))