fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var a = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    val q = readLine()!!.toInt()

    for (i in 1..q) {
        val (b, c) = readLine()!!.split(" ").map { it.toInt() }
        for (j in a.indices) {
            if (b == a[j]) {
                a[j] = c
            }
        }
        println(a.sum())
    }

}