import java.io.PrintWriter
import kotlin.math.abs

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val n = readInteger()
    val aList = readIntegerList()
    val aNumArray = IntArray(100001)
    for (a in aList) {
        aNumArray[a]++
    }
    var sum = aList.sum()
    val q = readInteger()
    repeat(q) {
        val (b, c) = readIntegerList()
        val bNum = aNumArray[b]
        aNumArray[b] = 0
        aNumArray[c] += bNum
        
        sum += c * bNum - b * bNum
        println(sum)
    }
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)
