#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ar[100000];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ar[i];
  int q;
  cin >> q;
  unordered_map<int, int> mp;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    mp[ar[i]]++;
    sum += ar[i];
  }
  while (q--) {
    int p, q;
    cin >> p >> q;
    if (mp.find(p) != mp.end()) {
      sum -= mp[p] * p;
      sum += mp[p] * q;
      mp[q] += mp[p];
      mp.erase(p);
    }
    cout << sum << endl;
  }
  return 0;
}
