use proconio::input;
use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        mut a: [u64; n],
        q: usize,
        bc: [(u64, u64); q],
    }
    let mut h = HashMap::new();
    for aj in a {
        *h.entry(aj).or_insert(0) += 1;
    }
    for i in 0..q {
        let mut hbv = 0;

        {
            let hb = (*(&mut h)).entry(bc[i].0).or_insert(0);
            hbv = *hb;
            *hb = 0;
        }

        let hc = (*(&mut h)).entry(bc[i].1).or_insert(0);
        *hc += hbv;

        let mut r = 0;
        for hj in &h {
            r += hj.0 * hj.1;
        }
        println!("{}", r);
    }
}
