import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector as V
import Data.Tuple (swap)
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.List (intercalate)

main :: IO ()
main = do
  let
    fromEdgesToAdjacencyVectorN :: Int -> [(Int, Int)] -> V.Vector [Int]
    fromEdgesToAdjacencyVectorN n = V.accum (flip (:)) (V.replicate n [])
    fromAdjacencyVectorToTree :: V.Vector [Int] -> Int -> Tree Int
    fromAdjacencyVectorToTree adjacency root = Node root (map (f root) (adjacency V.! root))
      where
        f :: Int -> Int -> Tree Int
        f p i = Node i (map (f i) . filter (/= p) $ adjacency V.! i)
    fromTreeToCumCounts counts tree = do
      v <- VU.thaw counts
      let
        f c (Node x ts) = do
                            VUM.write v x c'
                            mapM_ (f c') ts
          where
            c' = c + (counts VU.! x)
      f 0 tree
      VU.freeze v
  [n, q] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  abs <- sequence . replicate (n - 1) $ unsafeListToPair . map (pred . unsafeTextToInt) . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    adjacency = fromEdgesToAdjacencyVectorN n . ((++) <$> id <*> map swap) $ abs :: V.Vector [Int]
    tree = fromAdjacencyVectorToTree adjacency 0 :: Tree Int
  pxs <- sequence . replicate q $ ((,) <$> pred . fst <*> snd) . unsafeListToPair . map unsafeTextToInt . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    counts = VU.accum (+) (VU.replicate n 0) $ pxs :: VU.Vector Int
  cumCounts <- fromTreeToCumCounts counts tree
  putStrLn . intercalate " " . map show . VU.toList $ cumCounts

data Tree a = Node a [Tree a]

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair [x, y] = (x, y)
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}
