# abc070d: Transit Tree Path



n = int(eval(input()))



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

for _ in range(n-1):

    v1,v2,d = list(map(int, input().split()))

    v1,v2 = v1-1,v2-1

    T[v1].append([v1,v2,d])

    T[v2].append([v2,v1,d])



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



visit = [False]*(n)

depth = [0]*(n)

stack = [[-1,k-1,0]]

while stack:

    p,c,d = stack.pop()

    if visit[c]: continue

    visit[c] = True

    depth[c] = d

    if p>=0: depth[c] += depth[p]

    for pp,cc,dd in T[c]:

        if not visit[cc]: stack.append([pp,cc,dd])



for _ in range(q):

    v1,v2 = list(map(int, input().split()))

    print((depth[v1-1]+depth[v2-1]))
## abc070d: Transit Tree Path



n = int(eval(input()))



T = [{} for _ in range(n)]

for _ in range(n-1):

    v1,v2,d = list(map(int, input().split()))

    T[v1-1][v2-1] = d

    T[v2-1][v1-1] = d



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



visit = [False]*n

depth = [0]*n

stack = [[-1,k-1,0]]

while stack:

    p,c,d = stack.pop()

    if visit[c]: continue

    visit[c] = True

    depth[c] = d

    if p>=0: depth[c] += depth[p]

    for cc in list(T[c].keys()):

        if not visit[cc]: stack.append([c,cc,T[c][cc]])



for _ in range(q):

    v1,v2 = list(map(int, input().split()))

    print((depth[v1-1]+depth[v2-1]))
# abc070d: Transit Tree Path
n = int(eval(input()))
T = [[] for _ in range(n)]
for _ in range(n - 1):
    v1, v2, d = list(map(int, input().split()))
    v1, v2 = v1 - 1, v2 - 1
    T[v1].append([v1, v2, d])
    T[v2].append([v2, v1, d])
q, k = list(map(int, input().split()))
visit = [False] * (n)
depth = [0] * (n)
stack = [[-1, k - 1, 0]]
while stack:
    p, c, d = stack.pop()
    if visit[c]:
        continue
    visit[c] = True
    depth[c] = d
    if p >= 0:
        depth[c] += depth[p]
    for pp, cc, dd in T[c]:
        if not visit[cc]:
            stack.append([pp, cc, dd])
for _ in range(q):
    v1, v2 = list(map(int, input().split()))
    print((depth[v1 - 1] + depth[v2 - 1]))

## abc070d: Transit Tree Path
n = int(eval(input()))
T = [{} for _ in range(n)]
for _ in range(n - 1):
    v1, v2, d = list(map(int, input().split()))
    T[v1 - 1][v2 - 1] = d
    T[v2 - 1][v1 - 1] = d
q, k = list(map(int, input().split()))
visit = [False] * n
depth = [0] * n
stack = [[-1, k - 1, 0]]
while stack:
    p, c, d = stack.pop()
    if visit[c]:
        continue
    visit[c] = True
    depth[c] = d
    if p >= 0:
        depth[c] += depth[p]
    for cc in list(T[c].keys()):
        if not visit[cc]:
            stack.append([c, cc, T[c][cc]])
for _ in range(q):
    v1, v2 = list(map(int, input().split()))
    print((depth[v1 - 1] + depth[v2 - 1]))

-# abc070d: Transit Tree Path +## abc070d: Transit Tree Path -T = [[] for _ in range(n)] +T = [{} for _ in range(n)] -    v1, v2 = v1 - 1, v2 - 1 -    T[v1].append([v1, v2, d]) -    T[v2].append([v2, v1, d]) +    T[v1 - 1][v2 - 1] = d +    T[v2 - 1][v1 - 1] = d -visit = [False] * (n) -depth = [0] * (n) +visit = [False] * n +depth = [0] * n -    for pp, cc, dd in T[c]: +    for cc in list(T[c].keys()): -            stack.append([pp, cc, dd]) +            stack.append([c, cc, T[c][cc]])