#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::{i32, i64, i128, u32, u64, u128, f64};
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        n: usize,
        arr: [i64; n],
        q: usize,
        bcs: [(i64, i64); q],
    }
    let mut counter = HashMap::new();
    for a in arr { *counter.entry(a).or_insert(0) += 1; }
    for (b, c) in bcs {
        if let Some(mr) = counter.get_mut(&b) {
            let b = *mr;
            *mr = 0;
            *counter.entry(c).or_insert(0) += b;
        }
        println!("{}", counter.iter().map(|(k, v)| k * v).sum::<i64>());
    }
}
