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 sum (v: &Vec<u32>) -> u32 {
	let vec = v.to_vec();
	let mut ans: u32 = 0;
	for i in vec.iter() {
		ans += i;
	}
	ans
}

fn replace(v: Vec<u32>, f: u32, r: u32) -> Vec<u32> {
	let mut v = v.to_vec();
	for i in 0..v.len() {
		if v[i] == f {
			v[i] = r;
		}
	}
	v
}

fn main() {
	let mut scan = Scanner::default();
	let n: u32 = scan.next();
	let mut a: Vec<u32> = vec![];
	for _ in 0..n {
		a.push(scan.next());
	}
	let q: u32 = scan.next();
	for _ in 0..q {
		a = replace(a, scan.next(), scan.next());
		println!("{}", sum(&mut a));
	}
}
