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 = readLongList()
    val q = readInt()
    var sumA: Long = a.sum()
    val counter = Array(100001) { 0L }
    a.forEach {
        counter[it.toInt()] = counter[it.toInt()]+1
    }
    val res = mutableListOf<Long>()
    for (i in 0 until q) {
        val (b, c) = readIntList()
        val bNum = counter[b]
        counter[b] = 0L
        counter[c] += bNum
        val d: Long = c * bNum - bNum * b
        sumA += d
        res.add(sumA)
//        println(counter.sliceArray(0..10).joinToString(separator = ","))
    }
    res.forEach {
        println(it)
    }
}
