import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val A = Array(N) { sc.next().toInt() }
        val Anum = IntArray(100001)
        A.forEach {
            Anum[it]++
        }
        val Q = sc.next().toInt()
        var ans = A.sum()
        repeat(Q) {
            val B = sc.next().toInt()
            val C = sc.next().toInt()
            val r = C - B
            ans += Anum[B] * r
            Anum[C] += Anum[B]
            Anum[B] = 0
            pw.println(ans)
        }
    }
}
