fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main() {
    val n = readInt()
    val a = readIntList()
    val q = readInt()
    var sumA: Long = a.sum().toLong()
    val counter = Array(100001) { 0 }
    a.forEach {
        counter[it] += 1
    }
    val res = mutableListOf<Long>()
    for (i in 0 until q) {
        val (b, c) = readIntList()
        val bNum = counter[b]
        counter[b] = 0
        counter[c] += bNum
        val d = c * bNum - bNum * b
        sumA += d
//        println(sumA)
        res.add(sumA)
    }
    res.forEach {
        println(it)
    }
}
