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));
    }
    for(let i=0; i<BiCi.length; i++){
        let sum = 0;
        for(let j=0; j<Ai.length; j++){
            if(Ai[j] === BiCi[i][0]){
                Ai[j] = BiCi[i][1];
                sum += BiCi[i][1];
            } else {
                sum += Ai[j];
            }
        }
        console.log(sum);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));