function Main(input){
    const arr = input.split('\n');
    const N = Number(arr.shift());
    let Ai = arr.shift().split(' ').map(Number);
    const Q = Number(arr.shift());
    let BiCi = []
    for(let i=0; i<arr.length; i++){
        BiCi.push(arr[i].split(' ').map(Number));
    }
    let sum = Ai.reduce((a,b) => a+b);
    for(let i=0; i<BiCi.length; i++){
        let arrayNum = 0;
        Ai.forEach((val,index) => {
            if(val === BiCi[i][0]){ 
                arrayNum++;
                Ai[index] = BiCi[i][1];
            }
        });
        sum += arrayNum * Math.floor(BiCi[i][1] -BiCi[i][0]);
        console.log(sum);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));