n = int(eval(input()))

g = [[] for i in range(n)]

for i in range(n-1):

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

  a-=1;b-=1

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

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

q,k = list(map(int,input().split()))

k -= 1

con = [-1] * n

con[k] = 0

stack = [k]

while stack:

  cur = stack.pop()

  for i,j in g[cur]:

    if con[i] == -1:

      con[i] = con[cur] + j

      stack.append(i)

for i in range(q):

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

  x-=1;y-=1

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

import sys

input = sys.stdin.readline

n = int(eval(input()))

g = [[] for i in range(n)]

for i in range(n-1):

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

  a-=1;b-=1

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

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

q,k = list(map(int,input().split()))

k -= 1

con = [-1] * n

con[k] = 0

stack = [k]

while stack:

  cur = stack.pop()

  for i,j in g[cur]:

    if con[i] == -1:

      con[i] = con[cur] + j

      stack.append(i)

for i in range(q):

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

  x-=1;y-=1

  print((con[x]+con[y]))
n = int(eval(input()))
g = [[] for i in range(n)]
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    g[a].append([b, c])
    g[b].append([a, c])
q, k = list(map(int, input().split()))
k -= 1
con = [-1] * n
con[k] = 0
stack = [k]
while stack:
    cur = stack.pop()
    for i, j in g[cur]:
        if con[i] == -1:
            con[i] = con[cur] + j
            stack.append(i)
for i in range(q):
    x, y = list(map(int, input().split()))
    x -= 1
    y -= 1
    print((con[x] + con[y]))

import sys

input = sys.stdin.readline
n = int(eval(input()))
g = [[] for i in range(n)]
for i in range(n - 1):
    a, b, c = list(map(int, input().split()))
    a -= 1
    b -= 1
    g[a].append([b, c])
    g[b].append([a, c])
q, k = list(map(int, input().split()))
k -= 1
con = [-1] * n
con[k] = 0
stack = [k]
while stack:
    cur = stack.pop()
    for i, j in g[cur]:
        if con[i] == -1:
            con[i] = con[cur] + j
            stack.append(i)
for i in range(q):
    x, y = list(map(int, input().split()))
    x -= 1
    y -= 1
    print((con[x] + con[y]))

+import sys + +input = sys.stdin.readline