using static System.Console;
using System.Linq;
public static class Program{
  public static void Main(){
    ReadLine();
    var aArray = ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
    var q = long.Parse(ReadLine());
    var sum = aArray.Sum();
    for(long i = 0; i < q; ++i){
      var strs = ReadLine().Split(' ');
      var b = long.Parse(strs[0]);
      var c = long.Parse(strs[1]);
      for(int j = 0; j < aArray.Length; ++j){
        if(aArray[j] == b) {
          sum -= b;
          sum += c;
          aArray[j] = c;
        }
      }
    }
  }
}