{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad         (forM_, replicateM, when)
import           Control.Monad.ST      (ST)
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe            (fromJust)
import           Data.Vector           (Vector, (!))
import qualified Data.Vector           as V
import           Data.Vector.Mutable   (STVector)
import qualified Data.Vector.Mutable   as MV

main :: IO ()
main = do
  n <- readLn
  abcs <- replicateM (n - 1) getInts
  [q, k] <- getInts
  xys <- replicateM q getInts
  putStr . unlines . map show $ solve n abcs q k xys

solve :: Int -> [[Int]] -> Int -> Int -> [[Int]] -> [Int]
solve n abcs q k xys = map query xys where
  query [x, y] = ds ! (x - 1) + ds ! (y - 1)
  ds = depth n tree k
  tree = V.create $ do
    tree' <- MV.replicate n [] :: ST s (STVector s [(Int, Int)])
    forM_ abcs $ \[a, b, c] -> do
      let a' = a - 1
          b' = b - 1
      MV.modify tree' ((a', c):) b'
      MV.modify tree' ((b', c):) a'
    return tree'

depth :: Int -> Vector [(Int, Int)] -> Int -> Vector Int
depth n tree k = V.create $ do
  ds <- MV.new n :: ST s (STVector s Int)
  dfs ds tree (k - 1) (-1) 0
  return ds

dfs :: STVector s Int -> Vector [(Int, Int)] -> Int -> Int -> Int -> ST s ()
dfs ds tree v p d = do
  MV.write ds v d
  forM_ (tree ! v) $ \(w, c) -> do
    when (w /= p) .
      dfs ds tree w v $ d + c

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

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