use std::collections::HashMap;

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut map: HashMap<usize, usize> = HashMap::new();
    for i in 0..n {
        let tmp = a[i];
        let entry = map.entry(tmp).or_insert(0);
        *entry += 1;
    }
    let q = read::<usize>();
    let mut v: Vec<Vec<usize>> = Vec::new();
    for _ in 0..q {
        let bc = read_vec::<usize>();
        v.push(bc);
    }
    for i in 0..q {
        let bc = &v[i];
        let bentry = map.entry(bc[0]).or_insert(0);
        let tmp = *bentry;
        *bentry = 0;
        let centry = map.entry(bc[1]).or_insert(0);
        *centry += tmp;

        let mut ret = 0;
        for (k, v) in map.iter() {
            ret += k * v;
        }
        println!("{}", ret);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
