import Data.Char
import Control.Monad

import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM

main :: IO ()
main = do
  n <- readLn :: IO Int
  a <- map read . words <$> getLine :: IO [Int]

  v <- VM.replicate 100001 0 :: IO (VM.IOVector Int)

  forM_ a $ \x -> do
    VM.modify v (+1) x
  
  q <- readLn :: IO Int

  let
    f 0 ans = return ()
    f k ans = do
      [b, c] <- map read . words <$> getLine :: IO [Int]

      x <- VM.read v b
      VM.write v b 0
      VM.modify v (+x) c
    
      let ans' = ans + x * (c - b)

      print ans'
      f (k-1) ans'
      
  f q (sum a)
