const Main = input => {
    input = input.split("\n");
    const n = parseInt(input[0], 10);
    const a = input[1].split(" ").map(value => parseInt(value, 10));
    const q = parseInt(input[2], 10);
    const bc = [];
    for(let i = 0; i < q; i++) {
        bc.push(input[i + 3].split(" ").map(value => parseInt(value, 10)));
    }

    let total;
    for(let i = 0; i < q; i++) {
        total = 0;
        for(let j = 0; j < n; j++) {
            if(a[j] === bc[i][0]) {
                a[j] = bc[i][1];
            }

            total += a[j];
        }

        console.log(total);
    }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));