import java.util.*

fun main(args: Array<String>) {
    val reader = Scanner(System.`in`)
    var N = reader.nextInt()
    var valuesMap = mutableMapOf<Int, Int>()
    var currentSum = 0L

    repeat(N){
        val readValue = reader.nextInt()
        var count = valuesMap.getOrDefault(readValue, 0)
        valuesMap.put(readValue, count + 1)
        currentSum += readValue
    }
    var Q = reader.nextInt()
    repeat(Q){
        val b = reader.nextInt()
        val q = reader.nextInt()
        if(valuesMap.containsKey(b)){
            val bNum = valuesMap.getOrDefault(b, 0)
            val qNum = valuesMap.getOrDefault(q, 0)
            
            valuesMap.put(q, qNum + bNum)
            currentSum += (q - b)*bNum
            valuesMap.remove(b)
        }
        println(currentSum)
    }
}