import java.math.BigDecimal

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val numbers = MutableList(100001) { BigDecimal.ZERO }
    val input = readLine()!!.split(" ").map { it.toInt() }
    input.forEach { numbers[it] = numbers[it] + BigDecimal.ONE }
    val q = readLine()!!.toInt()
    var sum = input.sum().toBigDecimal()
    repeat(q) {
        val (b,c) = readLine()!!.split(" ").map { it.toInt() }
        val numB = numbers[b]
        numbers[b] = BigDecimal.ZERO
        numbers[c] += numB
        sum += (c-b).toBigDecimal() * numB
        println(sum)
    }
}
