fun main() = Thread(null, ::abc171d, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc171d() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }.toLongArray()

    val grouped = aList.groupBy { it }.mapValues { it.value.size }
        .toMutableMap().withDefault { 0 }
    var sum = aList.sum()
    val answer = StringBuilder()

    repeat(readLine()!!.toInt()) {
        val (b, c) = readLine()!!.split(' ').map { it.toLong() }
        val countOfB = grouped.getValue(b)
        sum -= (b - c) * countOfB
        answer.appendln(sum)
        grouped[c] = grouped.getValue(c) + countOfB
        grouped.remove(b)
    }

    print(answer)
}
