local List = {}
function List.new ()
    return {first = 0, last = -1}
end

function List.pushleft (list, value)
    local first = list.first - 1
    list.first = first
    list[first] = value
end

function List.pushright (list, value)
    local last = list.last + 1
    list.last = last
    list[last] = value
end

function List.popleft (list)
    local first = list.first
    local value = list[first]
    list[first] = nil
    list.first = first + 1
    return value
end

function List.popright (list)
    local last = list.last
    local value = list[last]
    list[last] = nil
    list.last = last - 1
    return value
end

function List.empty (list)
    return list.first > list.last
end

----------

local n=io.read("n")

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

for i=1,n-1 do
    local a,b,c=io.read("n","n","n")
    graph[a][b]=c
    graph[b][a]=c
end

local q,k=io.read("n","n")

local stack=List.new()
List.pushright(stack,{k,0})
local dist={[k]=0}

while not List.empty(stack) do
    local pop=List.popright(stack)
    local a=pop[1]
    local c=pop[2]
    for b,_ in pairs(graph[a]) do
        local nc=c+graph[a][b]
        if not dist[b] then
            dist[b]=nc
            List.pushright(stack,{b,nc})
        end
    end
end

for i=1,q do
    local x,y=io.read("n","n")
    print(dist[x]+dist[y])
end