import Control.Monad
import Data.Maybe
import Data.List
import qualified Data.IntMap as M

main :: IO ()
main = do
    n <- readLn
    ts <- replicateM (n-1) $ do
        [a,b,c] <- getInts
        return ((a,b),c)
    [q,k] <- getInts
    xys <- replicateM q $ do
        [x,y] <- getInts
        return (x,y)
    let t = build k ts
    mapM_ (print . solve t) xys

type Tree = M.IntMap Int

getInts :: IO [Int]
getInts = map read . words <$> getLine

build :: Int -> [((Int,Int),Int)] -> Tree
build k = worker M.empty [(k,0)]

worker :: Tree -> [(Int,Int)] -> [((Int,Int),Int)] -> Tree
worker acc [] ts = acc
worker acc ((p,w):stk) ts = let (ps,ch) = foldr (classify p w) ([],[]) ts
                                acc' = foldr (\(k,v) t -> M.insert k v t) acc ps
                                stk' = ps ++ stk
                            in worker acc' stk' ch

classify :: Int -> Int -> ((Int,Int),Int) -> ([(Int,Int)],[((Int,Int),Int)]) -> ([(Int,Int)],[((Int,Int),Int)])
classify p w ch@((a,b),c) (ps,cs) | p == a = ((b,w+c):ps,cs)
                                  | p == b = ((a,w+c):ps,cs)
                                  | otherwise = (ps,ch:cs)

solve :: Tree -> (Int, Int) -> Int
solve t (x,y) = fromJust $ (+) <$> M.lookup x t <*> M.lookup y t
