// https://atcoder.jp/contests/abc171/tasks/abc171_d

use proconio::input;

fn main() {
    input! {
      n: i32,
      a_s: [usize; n],
      q: i32,
      bcs: [(usize, usize); q],
    }
    let mut acc = vec![0; 100001];
    for &a in a_s.iter() {
        acc[a] += 1;
    }
    let mut sum = acc
        .iter()
        .enumerate()
        .fold(0, |pre, (i, &a)| pre + (i as u32) * (a as u32));
    for &(b, c) in bcs.iter() {
        let bb = acc[b];
        acc[c] += bb;
        acc[b] = 0;
        sum = (sum as i64 + bb as i64 * (c - b) as i64) as u32;
        println!("{}", sum);
    }
}
