import Control.Monad

getNumber :: String -> [Int]
getNumber xs = (read (fst h) :: Int) : case snd h of
                                         [] -> []
                                         (_:xs') -> getNumber xs'
  where h = break (== ' ') xs

getTaple :: String -> (Int,Int)
getTaple xs = (read $ fst h :: Int,(read.(\(_:xs) -> xs)) $ snd h)
  where h = break (== ' ') xs

replace :: [Int] -> (Int,Int) -> [Int]
replace xs (1,m) = m : (tail xs)
replace (x:xs) (n,m) = x : replace xs ((n - 1),m)

printTaples :: [Int] -> [(Int,Int)] -> IO ()
printTaples _ [] = return ()
printTaples xs (y:ys) = do
                      let p = sum $ replace xs y
                      putStrLn $ show p
                      printTaples xs ys

main :: IO ()
main = do
  num_ <- getLine
  nums <- fmap getNumber getLine :: IO [Int]
  drinks <- fmap read getLine :: IO Int
  numPares <- replicateM drinks $ do
                numP <- fmap getTaple getLine
                return numP
  printTaples nums numPares