fun main(args: Array<String>) {
    val n = readInt()
    val a = readIntList().toMutableList()
    val q = readInt()
    val arr = mutableListOf<Pair<Int, Int>>()
    repeat(q) {
        val (b, c) = readIntList()
        arr.add(Pair(b, c))
    }

    var sum = a.sum()
    for (i in 0 until q) {
        a.forEachIndexed { ind, v ->
            if (v == arr[i].first) {
                a[ind] = arr[i].second
                sum += arr[i].second - arr[i].first
            }
        }
        println(sum)
    }
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)