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

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

//https://onlinejudge.u-aizu.ac.jp/solutions/problem/ALDS1_5_B/review/2709881/arsenic28/Rust
trait Joinable {
    fn join(self, sep: &str) -> String;
}

fn main() {
    let n: u64 = read();
    let a: Vec<u64> = (0..n).map(|_| read()).collect();
    let mut map = HashMap::new();

    let mut sum: u64 = a.iter().sum();

    for i in a.iter() {
        let count = map.entry(*i).or_insert(0);
        *count += 1;
    }

    let q: usize = read();

    for _ in 0..q {
        let b: u64 = read();
        let c: u64 = read();

        let b_num = map.get(&b).unwrap();
        sum = sum - b_num * b + b_num * c;

        if let Some(num) = map.remove(&b) {
            *map.entry(c).or_insert(0) += num;
        }

        println!("{}", sum);
    }
}
