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