#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long temp;
  map<long long, long long> freq;
  long long acc = 0;
  for (long long i = 0; i < n; i++) {
    cin >> temp;
    acc += temp;
    if (freq.find(temp) == freq.end()) {
      freq[temp] = 1;
    } else {
      freq[temp]++;
    }
  }
  long long q;
  cin >> q;
  vector<long long> targets(q);
  map<long long, long long> replacer;
  map<long long, long long> replacer_diff;
  long long temp_1, temp_2;
  for (long long i = 0; i < q; i++) {
    cin >> temp_1 >> temp_2;
    targets[i] = temp_1;
    replacer[temp_1] = temp_2;
    replacer_diff[temp_1] = temp_2 - temp_1;
  }
  for (auto t : targets) {
    if (replacer_diff.find(t) != replacer_diff.end()) {
      acc += replacer_diff[t] * freq[t];
      cout << acc << endl;
      freq[replacer[t]] += freq[t];
      freq[t] = 0;
    } else {
      cout << acc << endl;
    }
  }
  return 0;
}
