use std::io;
use std::collections::HashMap;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("");
    let iter = buf.split_whitespace();
    let mut v: Vec<T> = Vec::new();
    for i in iter {
        v.push(i.parse().ok().unwrap());
    }
    v
}

fn main() {
    let mut map:HashMap<u64, u64> = HashMap::new();
    let n:u64 = procon_read()[0];
    let a:Vec<u64> = procon_read();
    let mut sum:u128 = 0;
    for i in a {
        match map.insert(i, 1) {
            Some(n) => {
                map.insert(i, n+1);
            },
            _ => (),
        }
        sum += i as u128;
    }
    let q:u64 = procon_read()[0];
    let mut s:Vec<u128> = Vec::new();
    for i in 0..q {
        let bc:Vec<u64> = procon_read();
        match map.insert(bc[0], 1) {
            Some(n) => {
                for j in 0..n {
                    sum = sum - bc[0] as u128 + bc[1] as u128;
                }
                map.remove(&bc[0]);
                let m = match map.insert(bc[1], n) {
                    Some(k) => k,
                    None => 0,
                };
                map.insert(bc[1], m+n);
            },
            None => (),
        }
        s.push(sum);
    }
    for i in s {
        println!("{}", i);
    }
}