import Data.Array.IO
import Control.Monad

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

main = do
  n <- readLn :: IO Int
  tree <- newArray (1,n) [] :: IO (IOArray Int [(Int,Integer)])

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

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

  dist <- newArray (1,n) (-1) :: IO (IOArray Int Integer)

  let calc i d = do
        nodes <- readArray tree i
        forM_ nodes $ \(next, c) -> do
          x <- readArray dist next
          when (x == -1) $ do
            writeArray dist next (d+c)
            calc next (d+c)

  writeArray dist k 0
  calc k 0

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