object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt
  val As = new Array[Long](100_001)
  val sum = (1 to N).map{_ =>
    val i = in.nextInt
     As(i) += 1
     i.toLong
   }.sum

  val Q = in.nextInt
  (1 to Q).foldLeft(sum) {(sum, i) =>
    val from = in.nextInt
    val to = in.nextInt
    val newSum = sum + (to - from) * As(from)
    println(newSum)
    As(to) += As(from)
    As(from) = 0
    newSum
  }
}