import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = (1..n).map { sc.nextLong() }
  val q = sc.nextInt()
  val bc = (1..q).map { Pair(sc.nextLong(), sc.nextLong()) }


  val map = mutableMapOf<Long, Long>()
  for (ai in a) {
    val tmp = map.getOrElse(ai) { 0 }
    map.put(ai, tmp + 1)
  }

  var nowSum = a.sum()

  val ans = mutableListOf<Long>()
  for (bci in bc) {
    val b = bci.first
    val c = bci.second

    val bsize = map.getOrElse(b) { 0L }
    map.put(b, 0L)
    val csize = map.getOrElse(c) { 0L }
    map.put(c, bsize + csize)


    val sum = nowSum + (c - b) * bsize
    ans.add(sum)

    nowSum = sum
  }


  println(ans.joinToString("\n"))

}


