import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString     as B
import           Data.List
import qualified Data.Set            as S
import qualified Data.Vector.Unboxed as VU

readInt :: IO [Int]
readInt = map read . words <$> getLine

readIntlines :: Int -> IO [[Int]]
readIntlines n = map (map read . words) <$> replicateM n getLine

main :: IO ()
main = do
    [n] <- readInt
    a <- readInt
    [q] <- readInt
    bc <- readIntlines q
    -- mapM_ (putStrLn . show) (solve a bc)
    mapM_ (print) (tail $ solve a bc)

solve :: [Int] -> [[Int]] -> [Int]
solve a bc = map sum $ scanl' f a bc
  where
      f acc b = let (ts, fs) = partition (head b==) acc
                 in replicate (length ts) (last b) ++ fs
