#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
use std::collections::HashMap;
fn main() {
    let _n: usize = read();
    let a: Vec<i32> = read_vec();
    let q: usize = read();
    let mut hm = HashMap::new();
    let mut ans = 0;
    for i in a {
        *hm.entry(i).or_insert(0) += 1;
        ans += i;
    }
    for _ in 0..q {
        let bc: Vec<i32> = read_vec();
        if let Some(&x) = hm.get(&bc[0]) {
            ans += (bc[1] - bc[0]) * x;
            *hm.entry(bc[1]).or_insert(0) += x;
            *hm.entry(bc[0]).or_insert(0) = 0;
        }
        println!("{}", ans);
    }
}
