import java.io.PrintWriter
import java.util.*

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val counter = Counter()
    nextIntList().forEach { a -> counter.add(a) }
    val Q = nextInt()
    repeat(Q) {
        val (B, C) = nextIntList()
        counter.move(B, C)
        println(counter.sum())
    }
}

class Counter {
    val map = HashMap<Int, Long>()

    fun add(k: Int, d: Long = 1L): Long {
        val v = map.getOrPut(k) { 0L }
        map[k] = v + d
        return v + d
    }

    fun move(a: Int, b: Int) {
        add(b, map.getOrDefault(a, 0L))
        map[a] = 0L
    }

    fun sum(): Long {
        var sum = 0L
        for ((k, v) in map) {
            sum += k * v
        }
        return sum
    }
}