import sys

sys.setrecursionlimit(10**7)



n = int(eval(input()))

l = [[] for _ in range(n)]

for _ in range(n-1):

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

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

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

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

dist = [-1]*n

dist[k-1] = 0

def dfs(v):

  for nv, c in l[v]:

    if dist[nv] == -1:

      dist[nv] = dist[v]+c

      dfs(nv)

dfs(k-1)

for _ in range(q):

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

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

sys.setrecursionlimit(10**7)



n = int(eval(input()))

l = [[] for _ in range(n)]

for _ in range(n-1):

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

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

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

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

dist = [-1]*n

dist[k-1] = 0

def dfs(v):

  for nv, c in l[v]:

    if dist[nv] == -1:

      dist[nv] = dist[v]+c

      dfs(nv)

dfs(k-1)

for _ in range(q):

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

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

import sys

sys.setrecursionlimit(10**7)
n = int(eval(input()))
l = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b, c = list(map(int, input().split()))
    l[a - 1].append([b - 1, c])
    l[b - 1].append([a - 1, c])
q, k = list(map(int, input().split()))
dist = [-1] * n
dist[k - 1] = 0


def dfs(v):
    for nv, c in l[v]:
        if dist[nv] == -1:
            dist[nv] = dist[v] + c
            dfs(nv)


dfs(k - 1)
for _ in range(q):
    x, y = list(map(int, input().split()))
    print((dist[x - 1] + dist[y - 1]))

import sys

sys.setrecursionlimit(10**7)
n = int(eval(input()))
l = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b, c = list(map(int, input().split()))
    l[a - 1].append((b - 1, c))
    l[b - 1].append((a - 1, c))
q, k = list(map(int, input().split()))
dist = [-1] * n
dist[k - 1] = 0


def dfs(v):
    for nv, c in l[v]:
        if dist[nv] == -1:
            dist[nv] = dist[v] + c
            dfs(nv)


dfs(k - 1)
for _ in range(q):
    x, y = list(map(int, input().split()))
    print((dist[x - 1] + dist[y - 1]))

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