import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    edges <- VU.replicateM (n-1) $ do
        [a,b,c] <- getIntList
        return (a-1,b-1,c)
    let tree :: V.Vector [(Int,Int)]
        tree = V.create $ do
            t <- VM.replicate n []
            VU.forM_ edges $ \(a,b,c) -> do
                VM.modify t ((b,c) :) a
                VM.modify t ((a,c) :) b
            return t
    [q,k] <- getIntList
    query <- VU.replicateM q $ do
        [x,y] <- getIntList
        return (x-1,y-1)
    let costs :: VU.Vector Int
        costs = VU.create $ do
            vec <- VUM.replicate n 0
            let dfs pv pc this = do
                    forM_ (filter ((/= pv) . fst) (tree V.! this)) $ \(child,c) -> do
                        VUM.write vec child (pc+c)
                        dfs this (pc+c) child
            dfs (k - 1) 0 (k - 1)
            return vec
    VU.forM_ query $ \(x,y) -> do
        print $ costs VU.! x + costs VU.! y