import java.util.*
import kotlin.collections.HashMap

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var kotlin=scan.nextLine().toInt()
    var a = scan.nextLine().split(" ").map{ it.trim().toLong() }.toTypedArray()
    var q=scan.nextLine().toInt()

    var map = HashMap<Long,Long>()
    var sum : Long = 0
    for(x in a)
    {
        if(map.containsKey(x))
            map.put(x,map.getValue(x)+1)
        else
            map.put(x,1)
        sum+=x
    }
    for(i in 1..q)
    {
        var (b,c) = scan.nextLine().split(" ").map{ it.trim().toLong() }.toTypedArray()
        var acount :Long = 0
        if(map.containsKey(b))
            acount = map.getValue(b)

        sum=sum - (b*acount)
        sum =sum + (acount*c)
        if(map.containsKey(c))
            map.put(c,map.getValue(c)+acount)
        else
            map.put(c,acount)
        println(sum)
    }
}
