import Data.Array.IO
import Data.Int
import qualified Data.Vector.Mutable as VM
import Control.Monad

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

main = do
  n <- readLn :: IO Int
  tree <- VM.new n :: IO (VM.IOVector [(Int,Int64)])
  forM_ [0..n-1] $ \i -> VM.write tree i []

  replicateM (n-1) $ do
    (a,b,c) <- getLine >>= return . (\(a:b:c:_) -> (read a, read b, read c)) . words :: IO (Int,Int,Int64)
    VM.read tree (a-1) >>= \x -> VM.write tree (a-1) ((b,c):x)
    VM.read tree (b-1) >>= \x -> VM.write tree (b-1) ((a,c):x)    

  (q:k:_) <- getLine >>= return . map read . words :: IO [Int]

  dist <- VM.new n :: IO (VM.IOVector Int64)
  forM_ [0..n-1] $ \i -> VM.write dist i (-1)

  let
    calc :: Int -> Int -> Int64 -> IO ()
    calc i p d = do
      nodes <- VM.read tree (i-1)
      forM_ nodes $ \(next, c) -> do
        when (next /= p) $ do
          VM.write dist (next-1) (d+c)
          calc next i (d+c)

  VM.write dist (k-1) 0
  calc k (-1) 0

  replicateM q $ do
    (x:y:_) <- getLine >>= return . map read . words :: IO [Int]
    mapM (VM.read dist) [x-1,y-1] >>= print . sum