use proconio::input;

fn d() {
    input! {
        n: usize,
        mut a: [i32; n],
        q: usize,
        mut bc: [(i32, i32); q],
    }
    let mut ans: Vec<i32> = Vec::with_capacity(q);

    for num in 0..q {
        a = a.iter().map(
            |i| {
                if *i == bc[num].0 {
                    return bc[num].1;
                }
                *i
            }).collect();
        ans.push(a.iter().sum());
    }
    for i in ans {
        println!("{}", i);
    }
}

fn main() {
    d();
}