fun main() {
    readLine() // skip
    val list = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    val q = readLine()!!.toInt()
    val list2 = (0 until q).map {
        val (b, c) = readLine()!!.split(" ").map { it.toInt() }
        b to c
    }
    list2.forEach { (b, c) ->
        list.replaceAll {
            if (it == b) {
                c
            } else {
                it
            }
        }

        println(list.sum())
    }
}