import Control.Monad
import qualified Data.Map as M
import qualified Data.IntMap as IM
import Data.List

type Graph = M.Map (Int, Int) Int
type Path = IM.IntMap 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 IM.! x + path IM.! y

dfs :: Graph -> Int -> Int -> Path
dfs graph k size = go 0 k 0 IM.empty
  where
    go depth current cost acc
      | depth == size = acc
      | IM.member current acc = 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
          foldl (\acc' (nxt, c') ->
                   go (depth+1) nxt (cost+c')
                                (IM.insert current cost acc')) acc cs
              
