use std::collections::HashMap;

macro_rules! get_one {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<$t>().unwrap()
    }};

    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_one!($t)).collect::<Vec<_>>()
    };
}
macro_rules! get_tuple {
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };

    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get_tuple!($($t),*)
        ).collect::<Vec<_>>()
    };
}
macro_rules! get_vec {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_vec!($t)).collect::<Vec<_>>()
    };
}
fn main() {
    let _ = get_one!(usize);
    let v_a = get_vec!(usize);
    let q = get_one!(usize);
    let v_bc = get_tuple!(usize, usize; q);

    let mut hm_a = HashMap::new();

    for a in v_a {
        *hm_a.entry(a).or_insert(0) += 1;
    }

    for (b, c) in v_bc {

        let k = hm_a.entry(b).or_insert(0);
        let kk = k.clone();
        *k = 0;
        *hm_a.entry(c).or_insert(0) += kk;

        let ans: i64 = hm_a.iter().map(|(&k, &v)| (k as i64) * (v as i64)).sum();
        println!("{}", ans);
    }

}
