n = io.read('*n')

e = {}
for i = 1, n do e[i] = {} end

for i = 1, n - 1 do
    local a, b, c = io.read('*n'), io.read('*n'), io.read('*n')
    e[a][#e[a] + 1] = { b, c }
    e[b][#e[b] + 1] = { a, c }
end

far = {}

dfs = function (u, p, d)
    far[u] = d
    for i = 1, #e[u] do if e[u][i][1] ~= p then
        dfs(e[u][i][1], u, d + e[u][i][2])
    end end
end

q, k = io.read('*n'), io.read('*n')

dfs(k, -1, 0)

for i = 1, q do print(far[io.read('*n')] + far[io.read('*n')]) end
