use proconio::{input, fastout};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! { n: usize, }
    let mut aa: HashMap<u32, u64> = HashMap::new();
    for _ in 0..n {
        input! { a: u32, }
        let count = aa.entry(a).or_insert(0);
        *count += 1;
    }
    input! { q: usize, }
    for _ in 0..q {
        input! { b: u32, c: u32, }
        let bc: u64;
        match aa.remove(&b) {
            None => {
                bc = 0;
            },
            Some(v) => {
                bc = v;
            },
        }
        let count = aa.entry(c).or_insert(0);
        *count += bc;
        let mut ans = 0;
        for (k, v) in &aa {
            ans += *k as u64 * v;
        }
        println!("{}", ans);
    }
}
