import java.util.*
import java.lang.Math.*


val readString: ()->String = {readLine()!!}
val readInt: ()->Int = {readLine()!!.toInt()}
val readLong: ()->Long = {readLine()!!.toLong()}
val readIntArray: ()->IntArray = {readLine()!!.split(' ').map{it.toInt()}.toIntArray()}
val readLongArray: ()->LongArray = {readLine()!!.split(' ').map{it.toLong()}.toLongArray()}
val errPrintln: (String)->Unit = {msg -> System.err.println(msg)}
val MOD = 1_000_000_007L
val INF = Int.MAX_VALUE/2
val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)


fun solve(A: IntArray, B: IntArray, C: IntArray): LongArray {
    val N = A.size
    val Q = B.size

    val hist = IntArray(100_001){0}
    for (i in 0 until N) {
        hist[A[i]] += 1
    }

    var sum = A.sum().toLong()
    val res = LongArray(Q){0}
    for (q in 0 until Q) {
        val db = hist[B[q]]
        hist[B[q]] = 0
        sum -= B[q].toLong() * db
        sum += C[q].toLong() * db
        hist[C[q]] += db
        res[q] = sum
    }

    return res
}


fun main(args: Array<String>) {
    val N = readInt()
    val A = readIntArray()
    val Q = readInt()
    val B = IntArray(Q)
    val C = IntArray(Q)
    for (i in 0 until Q) {
        val (b, c) = readIntArray()
        B[i] = b; C[i] = c
    }

    val ans = solve(A, B, C)
    for (a in ans) {
        println(a)
    }
}
