#![allow(unused_imports)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::collections::BinaryHeap;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}
impl<T: Iterator> IteratorExt for T {}

fn main() {
    let _n = read!(usize);
    let a = read!([usize]);
    let q = read!(usize);

    let mut v = vec![0; 100000+1];
    for &e in &a {
        v[e] += 1;
    }

    for _ in 0..q {
        let (b, c) = read!(usize, usize);
        let t = v[b];
        v[b] = 0;
        v[c] += t;

        let mut ans = 0;
        for i in 1..=100000 {
            ans += i * v[i];
        }
        println!("{}", ans);
    }
}

