import java.util.*

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()
    for(i in 1..q)
    {
        var (b,c) = scan.nextLine().split(" ").map{ it.trim().toLong() }.toTypedArray()
        var ans : Long =0
        for(i in 0..a.size-1)
        {
            if(a[i]==b)
            {
                ans+=c
                a[i]=c
            }
            else
                ans+=a[i]
        }
        println(ans)

    }
}
