#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> countFreq(vector<int>& v) {
  unordered_map<int, int> mp;
  for (int i = 0; i < v.size(); i++) mp[v[i]]++;
  return mp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, B, C, Q;
  long long s = 0;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; ++i) {
    cin >> v[i];
    s += v[i];
  }
  unordered_map<int, int> mp = countFreq(v);
  cin >> Q;
  while (Q--) {
    cin >> B >> C;
    if (mp[B] == -1) {
      mp[B] = -1;
      mp[C] = -1;
    } else if (mp[B] != -1 && mp[B] != 0) {
      s = s - (mp[B] * B) + (mp[B] * C);
      if (mp[C] == -1)
        mp[C] = mp[B];
      else
        mp[C] = mp[C] + mp[B];
      mp[B] = -1;
    }
    cout << s << endl;
  }
  return 0;
}
