let main = (input) => {
    let usrInput = input.split(/\n/)
    let array = usrInput[1].split(/\s+/).map(Number)
    let q = parseInt(usrInput[2]);
    let operations = usrInput.slice(3, 3 + q)
 
    for (let index = 0; index < operations.length; index++) {
        let operate = operations[index].split(/\s+/).map(Number)
        let bi = operate[0]
        let ci = operate[1]
        let sum = 0
        let jake = 0
 
        array.forEach((item) => {
            if (item == bi) {
                array[jake] = ci
            }
            jake++
        })
        console.log(operate)
        console.log(array)
 
        sum = array.reduce((prev, next, index, array) => prev + next)
        console.log(sum);
    }
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'))