#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int q;
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < q; i++) cin >> b[i] >> c[i];
  long long s = accumulate(a.begin(), a.end(), 0);
  vector<int> an(10000, 0);
  for (int i = 0; i < n; i++) an[a[i]]++;
  for (int i = 0; i < q; i++) {
    s += an[b[i]] * (c[i] - b[i]);
    an[c[i]] += an[b[i]];
    an[b[i]] = 0;
    cout << s << endl;
  }
}
