import Data.Array
import Control.Monad

main = do
  li <- getLine
  let [n,q] = map read $ words li
  bas <- forM [2..n] (\_ -> do
    li <- getLine
    let [a,b] = map read $ words li
    return (b,a)
    )
  pxs <- forM [1..q] (\_ -> do
    li <- getLine
    let [p,x] = map read $ words li
    return (p,x)
    )
  let ans = compute n q bas pxs
  putStrLn $ unwords $ map show ans

compute :: Int -> Int -> [(Int,Int)] -> [(Int,Int)] -> [Int]
compute n q bas pxs = elems sa
  where
    xa = accumArray (+) 0 (1,n) pxs
    parent = array (1,n) bas
    sa = listArray (1,n) ( xa ! 1 : [ xa ! i + sa ! (parent ! i) | i <- [2..n] ])
