import java.util.StringTokenizer
import java.io.PrintWriter

fun main() {
    val reader = System.`in`.bufferedReader()
    var tokenizer: StringTokenizer = StringTokenizer("")
    val writer = PrintWriter(System.out, false)
    
    fun next(): String {
        while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(reader.readLine())
        return tokenizer.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextDouble() = next().toDouble()
    fun nextLine() = reader.readLine()

    fun solve() {
        var n = nextInt()
        var arr = LongArray(n){next().toLong()}

        var sum = arr.sum()

        var map = mutableMapOf<Long,Long>()

        for (i in arr){
            map[i] = map.getOrDefault(i,0L) + 1
        }



        repeat(nextInt()){
            var b = next().toLong()
            var c=  next().toLong()

            if (b !in map)writer.println(sum)
            else {
                var diff = (c-b)*map[b]!!
                sum+=diff
                writer.println(sum)
                var v = map[b]!!
                map.remove(b)
                map[c] = map.getOrDefault(c,0) + v
            }


        }



    }

    solve()


}


