import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt
  var A = Array.fill(N)(sc.nextInt)
  val Q = sc.nextInt
  val BC = Array.fill(Q)((sc.nextInt, sc.nextInt))

  val count = Array.fill(100001)(0L)
  val sum = Array.fill(Q+1)(0L)
  A.foreach(x => {
    count(x) += 1
    sum(0) += x
  })

  for (i <- 0 until Q) {
    val (b, c) = BC(i)
    sum(i+1) = sum(i) + count(b) * (c - b)
    count(c) += count(b)
    count(b) = 0
    println(sum(i+1))
  }
}
