import qualified Data.IntMap as M

main = do
  li <- getLine
  let n = read li
  li <- getLine
  let as = map read $ words li
  li <- getLine
  let q = read li
  co <- getContents
  let bcs = map (l2p . map read . words) $ lines co
  let ans = compute n as q bcs
  mapM_ print ans

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

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

step :: M.IntMap Int -> (Int,Int) -> M.IntMap Int
step am (b,c) = M.mapKeysWith (+) f am
  where
    f k = if k == b then c else k

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