from collections import deque



def main():

  def p(a,b):

    if a < b:

      return (a,b)

    else:

      return (b,a)

  #input = open(0).readline

  N = int(eval(input()))

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

  C = {}

  D = [0] * N

  parent = [0]*N

  for i in range(N-1):

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

    a -= 1

    b -= 1

    E[a].append(b)

    E[b].append(a)

    C[p(a,b)] = c



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

  K -= 1

  parent[K] = K

  Q = deque()

  Q.append(K)



  while Q:

    u = Q.popleft()

    d = D[u]

    for v in E[u]:

      if parent[u] == v:

        continue

      parent[v] = u

      D[v] = d + C[p(u,v)]

      Q.append(v)



  for i in range(M):

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

    x -= 1

    y -= 1

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



main()

  

 
from collections import deque



def main():

  def p(a,b):

    if a < b:

      return (a,b)

    else:

      return (b,a)

  input = open(0).readline

  N = int(eval(input()))

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

  C = {}

  D = [0] * N

  parent = [0]*N

  for i in range(N-1):

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

    a -= 1

    b -= 1

    E[a].append(b)

    E[b].append(a)

    C[(a,b)] = c

    C[(b,a)] = c



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

  K -= 1

  parent[K] = K

  Q = deque()

  Q.append(K)



  while Q:

    u = Q.popleft()

    d = D[u]

    for v in E[u]:

      if parent[u] == v:

        continue

      parent[v] = u

      D[v] = d + C[(u,v)]

      Q.append(v)



  for i in range(M):

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

    x -= 1

    y -= 1

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



main()

  

 
from collections import deque


def main():
    def p(a, b):
        if a < b:
            return (a, b)
        else:
            return (b, a)

    # input = open(0).readline
    N = int(eval(input()))
    E = [[] for i in range(N)]
    C = {}
    D = [0] * N
    parent = [0] * N
    for i in range(N - 1):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        E[a].append(b)
        E[b].append(a)
        C[p(a, b)] = c
    M, K = list(map(int, input().split()))
    K -= 1
    parent[K] = K
    Q = deque()
    Q.append(K)
    while Q:
        u = Q.popleft()
        d = D[u]
        for v in E[u]:
            if parent[u] == v:
                continue
            parent[v] = u
            D[v] = d + C[p(u, v)]
            Q.append(v)
    for i in range(M):
        x, y = list(map(int, input().split()))
        x -= 1
        y -= 1
        print((D[x] + D[y]))


main()

from collections import deque


def main():
    def p(a, b):
        if a < b:
            return (a, b)
        else:
            return (b, a)

    input = open(0).readline
    N = int(eval(input()))
    E = [[] for i in range(N)]
    C = {}
    D = [0] * N
    parent = [0] * N
    for i in range(N - 1):
        a, b, c = list(map(int, input().split()))
        a -= 1
        b -= 1
        E[a].append(b)
        E[b].append(a)
        C[(a, b)] = c
        C[(b, a)] = c
    M, K = list(map(int, input().split()))
    K -= 1
    parent[K] = K
    Q = deque()
    Q.append(K)
    while Q:
        u = Q.popleft()
        d = D[u]
        for v in E[u]:
            if parent[u] == v:
                continue
            parent[v] = u
            D[v] = d + C[(u, v)]
            Q.append(v)
    for i in range(M):
        x, y = list(map(int, input().split()))
        x -= 1
        y -= 1
        print((D[x] + D[y]))


main()

-    # input = open(0).readline +    input = open(0).readline -        C[p(a, b)] = c +        C[(a, b)] = c +        C[(b, a)] = c -            D[v] = d + C[p(u, v)] +            D[v] = d + C[(u, v)]