import           Control.Monad
import           Data.IORef
import           Data.List.Split
import           Data.Maybe
import           Data.List

main :: IO ()
main = do
  n <- readLn
  ts <- map read . words <$> getLine
  m <- readLn
  pxs <- replicateM m $ map read . words <$> getLine

  forM_ [(p, x) | (p:x:_) <- pxs] $ \px -> do
    let s = sum (solve ts px [0..n - 1] [])
    print s


solve :: [Int] -> (Int, Int) -> [Int] -> [Int] -> [Int]
solve _ _ [] ans = ans
solve ts (p, x) (i:is) ans
  | i == p - 1 = solve ts (p, x) is ans ++ [x]
  | otherwise = solve ts (p, x) is ans ++ [ts !! i]

