#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1000000000000000000;
const double PI = acos(-1);
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> mp;
  long long int sum = 0;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    mp[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  vector<long long int> ans(q);
  for (int i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    if (mp.count(b)) {
      int tmp = mp[b];
      sum -= b * mp[b];
      sum += c * mp[b];
      mp.erase(b);
      if (mp.count(c)) {
        mp[c] += tmp;
      } else {
        mp.insert(make_pair(c, tmp));
      }
    }
    ans[i] = sum;
  }
  for (int i = 0; i < (q); i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
