#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N;
  multiset<long long> A;
  long long Q;
  long long ans = 0;
  cin >> N;
  for (long long i = 0; i < N; i++) {
    long long Ain;
    cin >> Ain;
    ans += Ain;
    A.insert(Ain);
  }
  cin >> Q;
  for (long long i = 0; i < Q; i++) {
    long long a, b;
    cin >> a >> b;
    while (A.find(a) != A.end()) {
      A.erase(A.find(a));
      A.insert(b);
      ans -= a;
      ans += b;
    }
    cout << ans << endl;
  }
}
