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)

{-
素直なつくりはやめて、最初にトータル数えて、
後は、mapも更新しながら、bの個数を数えて差分だけ計算する
-}

compute :: Int -> [Int] -> Int -> [(Int,Int)] -> [Int]
compute n as q 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
