"use strict";

function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    let n = parseInt(input[0], 10);
    let a = input[1].split(" ").map(str => parseInt(str, 10));
    let q = parseInt(input[2], 10);
    let bc;
    a.sort(compareFunc);    //昇順に並べ替え
    let s;

    for (let i = 0; i < q; i++) {
        bc = input[i + 3].split(" ").map(str => parseInt(str, 10));
        //bc[0] と一致する要素を探す
        //全てbc[1]に置き換える

        if (a.some(num => num === bc[0])) {
            a[a.indexOf(bc[0])] = bc[1];
        }
        s = a.reduce((a, x) => a += x, 0);
        console.log(s);
    }
}


function compareFunc(a, b) {
    return a - b;
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));