"use strict";

function main(arg) {
    lines = arg.split("\n")
    const N = Number(lines[0])
    let A = lines[1].split(" ").map(x=>Number(x))
    const Q = Number(lines[2])
    lines.shift()
    lines.shift()
    lines.shift()
    const B = lines.map(x=>Number(x.split(" ")[0]))
    const C = lines.map(x=>Number(x.split(" ")[1]))
    
    let sum = []
    sum[0] = A.reduce((a,b)=>a+b)//initial summation
    A.sort()
    /*
    for(let i=0; i<Q; i++) {
        let dif = 0
        for(let j=0; j<N; j++) {
            if(A[j]===B[i]) {
                A[j] = C[i]
                dif = dif + (C[i] - B[i])
            }
        }
        sum[i+1] = sum[i] + dif
    }
    sum.shift()
    console.log(sum.join("\n"))
    */
}

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