use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let mut arr:Vec<u64> = (0..n).map(|_| read()).collect();
    let q:usize = read();
    let len = arr.len();
    for _ in 0..q {
        let x:u64 = read();
        let y:u64 = read();
        arr.retain(|&i| i != x);
        let mut tmp = vec![y; len-arr.len()];
        arr.append(&mut tmp);
        println!("{}", arr.iter().sum::<u64>());
    }
}
