fun main() {
    readLine()!!.toInt()
    val list = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    val q = readLine()!!.toInt()
    for (i in 1..q) {
        val (b, c) = readLine()!!.split(" ").map {it.toInt()}
        for ((index, number) in list.withIndex()) {
            if (number == b) {
                list[index] = c
            }
        }

        val sum = list.sum()
        println(sum)

    }


}