fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toLong() }.toMutableList()
    val q = readLine()!!.toInt()
    repeat(q) {
        val (b,c) = readLine()!!.split(" ").map { it.toLong() }
        a.forEachIndexed { index, l -> if (l == b) a[index] = c }
        println(a.reduce { acc, i -> acc + i })
    }
}
