#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

fn map_sum(map: &HashMap<usize, usize>) -> usize {
    let mut sum = 0;
    
    for (k, v) in map.iter() {
        sum += k * v
    }
    
    sum
}


#[fastout]
fn main() {
    input!{
        n: usize,
        a_vec: [usize; n],
        q: usize,
        bc_vec: [(usize, usize); q],
    }

    let mut map: HashMap<usize, usize> = HashMap::new();
    
    for a in a_vec.iter() {
        *map.entry(*a).or_insert(0) += 1;
    }

    for query in bc_vec.iter() {
        match &map.get(&query.0) {
            Some(x) => { *map.entry(query.1).or_insert(0) += **x; *map.get_mut(&query.0).unwrap() = 0; println!("{}", map_sum(&map))},
            None => println!("{}", map_sum(&map)),
        }
        // dbg!(&map);
        
    }

    println!("", );
}
