#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long x, n, q, sum = 0, a, b;
  cin >> n;
  map<int, int> mp;
  map<int, int>::iterator it, it2;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    mp[x]++;
  }
  for (it = mp.begin(); it != mp.end(); it++) {
    sum += (it->first * it->second);
  }
  cin >> q;
  while (q--) {
    cin >> a >> b;
    it = mp.find(a);
    sum -= (it->first * it->second);
    int temp = it->second;
    it2 = mp.find(b);
    if (it2 == mp.end()) {
      mp[b] = temp;
      sum += (b * temp);
    } else {
      sum -= (it2->first * it2->second);
      int temp2 = it2->second;
      mp[b] = temp + temp2;
      sum += (b * (temp + temp2));
    }
    mp.erase(it);
    cout << sum << "\n";
  }
  return 0;
}
