#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long q, n, m, sum = 0, b, c;
  cin >> n;
  map<long long, long long> data;
  for (int i = 0; i < n; ++i) {
    cin >> m;
    sum += m;
    data[m]++;
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    long long count = data[b];
    if (count > 0) {
      data[b] = 0;
      data[c] = count;
      sum -= b * count;
      sum += c * count;
    }
    cout << sum << "\n";
  }
  return 0;
}
