main :: IO ()
main = do
    _ <- getLine 
    xs <- map (read :: String -> Int) . words <$> getLine
    q <- readLn
    analyze q xs
        where
            analyze n xs = do
                [b, c] <- map (read :: String -> Int) . words <$> getLine
                let res = replace b c xs
                putStrLn $ show $ sum res
                if n == 1
                    then return ()
                    else analyze (n - 1) res
            replace _ _ [] = []
            replace tar rep (x:xs)
                | tar == x  = rep : replace tar rep xs
                | otherwise = x : replace tar rep xs