use std::io::stdin;

#[derive(Default)]
struct Scanner {
	buffer: Vec<String>
}

impl Scanner {
	fn next<T: std::str::FromStr> (&mut self) -> T {
		loop {
			if let Some(token) = self.buffer.pop() {
				return token.parse().ok().expect("Failed parse");
			}
			let mut input = String::new();
			stdin().read_line(&mut input).expect("Failed read");
			self.buffer = input.split_whitespace().rev().map(String::from).collect();
		}
	}
}

fn main() {
	let mut scan = Scanner::default();
	let n: usize = scan.next();
	let mut a: [usize; 10005] = [0; 10005];
	let mut ans: usize = 0;
	let mut x: usize;
	let mut y: usize;
	for _ in 0..n {
		x = scan.next();
		a[x] += 1;
		ans += x;
	}
	let q: u32 = scan.next();
	for _ in 0..q {
		x = scan.next();
		ans -= x * a[x];
		y = a[x];
		a[x] = 0;
		x = scan.next();
		ans += x * y;
		a[x] += y;
		println!("{}", ans);
	}
}
