import Data.Bits
import Data.List
import Data.Foldable(foldlM)
import Data.Maybe(fromJust)
import Control.Monad
import Data.Array as A ((!),accumArray)
import Data.Graph
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as VM
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Char8 as BS

toTuple :: [a] -> (a,a)
toTuple (x:y:_) = (x,y)
toTuple _ = undefined

getInt :: IO Int
getInt = fst . fromJust. BS.readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile (== ' ')) <$> BS.getLine

getLineB :: (Read a) => IO [a] --直接入力
getLineB = map (read.BS.unpack) . BS.words <$> BS.getLine

build :: Int -> Int -> [(Int,(Int,Int))] -> V.Vector Int
build s n ls = runST $ do
  vec <- VM.replicate (n+1) maxBound
  VM.write vec s 0
  sub vec s 0
  V.freeze vec
  where
    graph = A.accumArray (flip (:)) [] (1,n) ls
    sub vec s par = do
      forM_ (graph A.! s) $ \(vw,v) -> do
        d  <- VM.read vec v
        sd <- VM.read vec s
        if d > sd + vw && v /= par then VM.write vec v (sd+vw)
          else return ()
      --V.freeze vec >>= \vec -> traceShowM (graph A.! s, vec)
      forM_ (graph A.! s) $ \(_,v) -> if v == par then return () else sub vec v s

solve :: Int -> V.Vector Int -> IO ()
solve q vec = do
  replicateM_ q $ do
    [x,y] <- getIntList
    print $ (vec V.! x) + (vec V.! y)

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- fmap concat $ replicateM (n-1) $ do
    [a,b,c] <- getIntList
    return [(a,(c,b)),(b,(c,a))]
  [q,k] <- getIntList
  solve q $ build k n as
