#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  long long ans=0;
  cin >> n;
  vector<int> cnt(100000);
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    ans += a.at(i);
    cnt(a.at(i))++;
  }
  sort(a.begin(),a.end());
  int q;
  cin >> q;
  vector<int> b(q),c(q);
  for(int i=0;i<q;i++){
    cin >> b.at(i) >> c.at(i);
  }
  
  for(int i=0;i<q;i++){
    if(count(b.at(i)) == 0) cout << ans << endl;
    else {
      ans -= cnt(b.at(i))*b.at(i);
      ans += cnt(b.at(i))*c.at(i);
      cnt(c.at(i)) += cnt(b.at(i));
      cnt(b.at(i)) = 0;
      cout << ans << endl;
    }
  }
     
  return 0;
}
