// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: i64,
        mut a: [i64; n],
        q: i64,
    }

    let mut sum = 0;
    for i in &a {
        sum += i;
    }

    for _i in 0..q {
        input! {
            b: i64,
            c: i64,
        }
        let d = c - b;
        for j in 0..n {
            if a[j as usize] == b {
                a[j as usize] = c;
                sum += d;
            }
        }
        println!("{}", sum);
    }
}
