from collections import defaultdict



N = int(eval(input()))

E = defaultdict(list)

W = dict()



for i in range(N-1):

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

  E[a].append(b)

  E[b].append(a)

  W[(a,b)] = c

  W[(b,a)] = c



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



costs = [float('inf')]*(N+1)

costs[K] = 0



stack = [K]



while stack:

  s = stack.pop()

  for t in E[s]:

    if costs[t] > costs[s] + W[(s,t)]:

      costs[t] = costs[s] + W[(s,t)]

      stack.append(t)



for i in range(Q):

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

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


N = int(eval(input()))

E = [[] for _ in range(N)]



for i in range(N-1):

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

  a -= 1

  b -= 1

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

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



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

K -= 1

costs = [None]*N

costs[K] = 0



stack = [K]



while stack:

  s = stack.pop()

  c = costs[s]

  for t,d in E[s]:

    if costs[t] is None:

      costs[t] = c + d

      stack.append(t)



for i in range(Q):

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

  print((costs[x-1]+costs[y-1]))
from collections import defaultdict

N = int(eval(input()))
E = defaultdict(list)
W = dict()
for i in range(N - 1):
    a, b, c = list(map(int, input().split()))
    E[a].append(b)
    E[b].append(a)
    W[(a, b)] = c
    W[(b, a)] = c
Q, K = list(map(int, input().split()))
costs = [float("inf")] * (N + 1)
costs[K] = 0
stack = [K]
while stack:
    s = stack.pop()
    for t in E[s]:
        if costs[t] > costs[s] + W[(s, t)]:
            costs[t] = costs[s] + W[(s, t)]
            stack.append(t)
for i in range(Q):
    x, y = list(map(int, input().split()))
    print((costs[x] + costs[y]))

N = int(eval(input()))
E = [[] for _ in range(N)]
for i in range(N - 1):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    E[a].append((b, c))
    E[b].append((a, c))
Q, K = list(map(int, input().split()))
K -= 1
costs = [None] * N
costs[K] = 0
stack = [K]
while stack:
    s = stack.pop()
    c = costs[s]
    for t, d in E[s]:
        if costs[t] is None:
            costs[t] = c + d
            stack.append(t)
for i in range(Q):
    x, y = list(map(int, input().split()))
    print((costs[x - 1] + costs[y - 1]))

-from collections import defaultdict - -E = defaultdict(list) -W = dict() +E = [[] for _ in range(N)] -    E[a].append(b) -    E[b].append(a) -    W[(a, b)] = c -    W[(b, a)] = c +    a -= 1 +    b -= 1 +    E[a].append((b, c)) +    E[b].append((a, c)) -costs = [float("inf")] * (N + 1) +K -= 1 +costs = [None] * N -    for t in E[s]: -        if costs[t] > costs[s] + W[(s, t)]: -            costs[t] = costs[s] + W[(s, t)] +    c = costs[s] +    for t, d in E[s]: +        if costs[t] is None: +            costs[t] = c + d -    print((costs[x] + costs[y])) +    print((costs[x - 1] + costs[y - 1]))