import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Char
import Data.IORef
import Data.List
import Data.Maybe

main = do
  n <- getInt
  as <- getIntVec n
  v <- MV.replicate (10^5) 0 :: IO (MV.IOVector Int)
  s <- newIORef 0
  V.forM_ as $ \i -> do
    modifyIORef s (+i)
    MV.modify v (+1) i
  q <- getInt
  replicateM_ q $ do
    (b, c) <- getIntPair
    m <- MV.read v b
    modifyIORef s (+ ((c - b) * m))
    MV.write v b 0
    MV.modify v (+m) c
    print =<< readIORef s

  
getInt :: IO Int
getInt = readLn

second :: (b -> c) -> (a, b) -> (a, c)
second f (a, b) = (a, f b)

readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = fmap (second BS.tail) . BS.readInt

getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

getIntPair :: IO (Int, Int)
getIntPair = do
  v <- getIntVec 2
  return (v V.! 0, v V.! 1)
