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