import Control.Monad
import qualified Data.Map as Map

main = do
    t <- readLn :: IO Int
    g <- replicateM (t - 1) (fmap (map read . words) getLine :: IO [Int])
    (t : k : _) <- fmap (map read . words) getLine :: IO [Int]
    q <- replicateM t (fmap (map read . words) getLine :: IO [Int])
    mapM_ print $ solve4 g k q

solve4 :: [[Int]] -> Int -> [[Int]] -> [Int]
solve4 g k q = foldr f [] q
  where
    f (from : to : _) acc = let Just d1 = Map.lookup from lst; Just d2 = Map.lookup to lst in (d1 + d2) : acc
      where lst = Map.fromList $ dfs k (-1) 0 (tree g)

dfs v p d g = (v, d) : (foldl dfs' [] (let Just ns = Map.lookup v g in ns))
  where
    dfs' acc (to, cost)
        | to == p   = acc
        | otherwise = acc ++ dfs to v (d + cost) g

tree = foldr (\(a : b : c : _) -> add (b, a, c) . add (a, b, c)) $ Map.fromList []
  where
    add (a, b, c) acc = case Map.lookup a acc of
        Nothing    -> Map.insert a [(b, c)] acc
        Just nodes -> Map.insert a ((b, c) : nodes) acc
