import abc171.MultiSet.Companion.multiSetOf

fun main() = Thread(null, ::abc171d, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc171d() {
    readLine()
    val aList = readLine()!!.split(' ').map { it.toLong() }

    val ms = multiSetOf(aList)
    var sum = aList.sum()
    val answer = StringBuilder()

    repeat(readLine()!!.toInt()) {
        val (b, c) = readLine()!!.split(' ').map { it.toLong() }
        val countOfB = ms.count(b)
        
        sum -= (b - c) * countOfB
        answer.appendln(sum)
        
        ms.add(c, countOfB)
        ms.remove(b)
    }

    print(answer)
}

@Suppress("unused", "MemberVisibilityCanBePrivate")
abstract class Countable<K>(protected open val map: MutableMap<K, Int>) {
    fun add(k: K, v: Int = 1) = map.inc(k, v)
    fun remove(k: K, v: Int = 1) = map.dec(k, v)
    fun removeAll(k: K) = map.remove(k)
    fun contains(k: K) = map.contains(k)
    fun count(k: K) = map[k] ?: 0
    fun isEmpty() = map.isEmpty()
    fun isNotEmpty() = !isEmpty()

    protected fun <K> MutableMap<K, Int>.inc(k: K, v: Int) = merge(k, v, Int::plus)
    protected fun <K> MutableMap<K, Int>.dec(k: K, v: Int) =
        if ((this[k] ?: 0) <= v) remove(k) else merge(k, v, Int::minus)

    abstract override fun toString(): String
    abstract override fun hashCode(): Int
    abstract override fun equals(other: Any?): Boolean
}

@Suppress("unused", "MemberVisibilityCanBePrivate")
class MultiSet<K>(override val map: MutableMap<K, Int> = mutableMapOf()) : Countable<K>(map) {
    companion object {
        fun <K> multiSetOf() = MultiSet<K>()
        fun <K> multiSetOf(iterable: Iterable<K>) = multiSetFromGroup(iterable.groupBy { it })
        fun <K> multiSetOf(vararg args: K) = multiSetOf(args.toList())
        fun <K> multiSetFromGroup(map: Map<K, List<K>>) = multiSetFromCount(map.mapValues { it.value.size })
        fun <K> multiSetFromCount(map: Map<K, Int>) = MultiSet(map.toMutableMap())
    }

    override fun toString() = "MultiSet(map=$map)"
    override fun hashCode() = map.hashCode()
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as MultiSet<*>
        return map == other.map
    }
}

@Suppress("unused", "MemberVisibilityCanBePrivate")
class SortedMultiSet<K : Comparable<K>>(override val map: java.util.SortedMap<K, Int> = sortedMapOf()) :
    Countable<K>(map) {
    fun min() = if (map.isNotEmpty()) map.firstKey() else null
    fun max() = if (map.isNotEmpty()) map.lastKey() else null

    companion object {
        fun <K : Comparable<K>> sortedMultiSetOf() = SortedMultiSet<K>()
        fun <K : Comparable<K>> sortedMultiSetOf(vararg args: K) = sortedMultiSetOf(args.toList())
        fun <K : Comparable<K>> sortedMultiSetOf(iterable: Iterable<K>) =
            sortedMultiSetFromGroup(iterable.groupBy { it })

        fun <K : Comparable<K>> sortedMultiSetFromGroup(map: Map<K, List<K>>) =
            sortedMultiSetFromCount(map.mapValues { it.value.size })

        fun <K : Comparable<K>> sortedMultiSetFromCount(map: Map<K, Int>) = SortedMultiSet(map.toSortedMap())
    }

    override fun hashCode() = map.hashCode()
    override fun toString() = "SortedMultiSet(map=$map)"
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false
        other as SortedMultiSet<*>
        return map == other.map
    }
}
