import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import qualified Data.IntMap as M

main = do
  BS.getLine
  li <- BS.getLine
  let as = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  BS.getLine
  co <- BS.getContents
  let bcs = map (l2p . unfoldr (BS.readInt . BS.dropWhile isSpace)) $ BS.lines co
  let ans = compute as bcs
  mapM_ print ans

l2p [b,c] = (b,c)

compute :: [Int] -> [(Int,Int)] -> [Int]
compute as bcs = map snd $ tail $ scanl step (am, total am) bcs
  where
    am = M.fromListWith (+) [ (a,1) | a <- as ]

step :: (M.IntMap Int, Int) -> (Int,Int) -> (M.IntMap Int, Int)
step (am, sum0) (b,c) = (M.mapKeysWith (+) f am, sum1)
  where
    f k = if k == b then c else k
    sum1 = case M.lookup b am of
      Just n  -> sum0 + n * (c - b)
      Nothing -> sum0

total :: M.IntMap Int -> Int
total am = M.foldrWithKey' f 0 am
  where
    f k n acc = k*n + acc
