import Control.Monad
import qualified Data.Map as M
--import qualified Data.IntMap as IM
import Data.Array.ST
import Data.Array.IArray
import Data.List
import Control.Monad.ST
import Debug.Trace

type Graph = M.Map (Int, Int) Int
type PathST s = STArray s Int Int
type Path = Array Int Int 

main :: IO ()
main = do
  n <- readLn :: IO Int
  ns <- replicateM (n - 1) $ do
    [a, b, c] <- getInts
    return [((a, b), c), ((b, a), c)]
  [q, k] <- getInts
  qs <- replicateM q $ do
    [a, b] <- getInts
    return (a, b)
  let graph = M.fromAscList $ sort $ concat ns :: Graph
      path = dfs graph k n
      ans = solve qs path
--  print path
  mapM_ print ans
  
getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: [(Int, Int)] -> Path -> [Int]
solve qs path = map f qs
  where
    f (x, y) = path ! x + path ! y

dfs :: Graph -> Int -> Int -> Path
dfs graph k size = runST $ do
  arr <- newArray (1, size) (-1) :: ST s (PathST s)
  writeArray arr k 0
  arr' <- go 0 k 0 arr
  freeze arr'
  where
    go :: Int -> Int -> Int -> PathST s -> ST s (PathST s)
    go depth current cost acc
      | depth == size = return acc
      | otherwise =
        let cs = filter ((/= -1) . fst) $
              map (\(a, b) ->
                        case M.lookup (a, b) graph of
                          Nothing -> (-1, -1)
                          Just x -> (b, x))
                 $ zip (repeat current) [1..size] in do
          cs' <- filterM (\(nxt, _) -> do
                             v <- readArray acc nxt
--                             trace (show (nxt, v)) (return ())
                             return (v == -1)) cs
          foldM (\acc' (nxt, c') -> do
                      v <- readArray acc' nxt
--                      trace (show v) (return ())
                      if v /= -1
                        then return acc'
                        else do
                        writeArray acc' nxt (cost+c')
                        --trace (show nxt) (return ())
                        go (depth+1) nxt (cost+c') acc') acc cs'
            
