import Control.Monad
import qualified Data.IntMap.Strict as IM

nums = map read . words

main = do
  n <- readLn
  es <- map nums <$> replicateM (n - 1) getLine
  [q, k] <- nums <$> getLine
  xys <- map nums <$> replicateM q getLine
  forM_ xys (print . solve $ dist k es)
  
dist k [] = IM.singleton k 0
dist k (e:es)
  | IM.member a d = IM.insert b (d IM.! a + c) d
  | IM.member b d = IM.insert a (d IM.! b + c) d
  | otherwise = dist k (es ++ e)
    where
    [a, b, c] = e
    d = dist k es

solve d [x, y] = d IM.! x + d IM.! y
  

