import qualified Data.IntMap.Lazy as IM
main = do
  getLine
  nts <- IM.fromList . zip [1..] . map read . words <$> getLine
  getLine
  pxs <- f . map read . words <$> getContents
  mapM_ print [ IM.foldr (+) 0 (IM.union (IM.Singleton p x) nts) | (p, x) <- pxs ]
  
f [] = []
f (p:x:pxs) = (p, x) : f pxs