#include <bits/stdc++.h>
using namespace std;
int n, q;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vector<int> a(n);
  vector<int> frec(1e5 + 5, 0);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    frec[a[i]]++;
  }
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i];
    cin >> c[i];
    if (frec[b[i]]) {
      sum -= (b[i] * frec[b[i]]);
      sum += frec[b[i]] * c[i];
      frec[c[i]] += frec[b[i]];
      frec[b[i]] = 0;
    }
    cout << sum << "\n";
  }
  return 0;
}
