#![allow(non_snake_case)]

use proconio::input;

fn main() {
    input! {
        N: usize,
        mut A: [u64; N],
        Q: u64,
        BC: [[u64; 2]; Q],
    }

    for bc in BC.iter() {
        let b = bc[0];
        let c = bc[1];

        for a in A.iter_mut() {
            if *a == b {
                *a = c;
            }
        }
        println!("{}", A.iter().sum::<u64>());
    }
}
