#include <bits/stdc++.h>
using namespace std;
signed main() {
  vector<int> count(100000 * 11);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    count[a[i]]++;
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < (q); ++i) cin >> b[i] >> c[i];
  long long sum = 0;
  for (int i = 0; i < (n); ++i) sum += a[i];
  for (int j = 0; j < (q); ++j) {
    int& bj = b[j];
    int& cj = c[j];
    int c = count[bj];
    sum -= bj * c;
    sum += cj * c;
    count[bj] = 0;
    count[cj] += c;
    cout << sum << endl;
  }
  return 0;
}
