fn d() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let mut n = input.trim_right();

    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let mut a = input.trim_right().trim_right().split_whitespace().
        map(|c| c.parse::<i32>().unwrap()).
        collect::<Vec<i32>>();

    let mut a_total = a.iter().sum::<i32>() as i64;

    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let mut q = input.trim_right().parse::<usize>().unwrap();

    for i in 0..q {
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        let mut bc = input.trim_right().trim_right().split_whitespace().
            map(|c| c.parse::<i32>().unwrap()).
            collect::<Vec<i32>>();

        let mut n = 0;
        a = a.iter().map(|c|{
            if *c == bc[0] {
                n += 1;
                return bc[1];
            }
            else {
                return *c;
            }
        }).collect::<Vec<i32>>();
        a_total += ((bc[1] - bc[0]) * n) as i64;
        println!("{}", a_total);
    }
}

fn main() {
    d();
}