#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), c(q);
  for (int i = 0; i < (q); i++) {
    cin >> b[i];
    cin >> c[i];
  }
  vector<int> all(100005);
  int sum = 0;
  for (int i = 0; i < (n); i++) {
    all[a[i]]++;
    sum += a[i];
  }
  for (int i = 0; i < (q); i++) {
    sum += (c[i] - b[i]) * all[b[i]];
    all[c[i]] += all[b[i]];
    all[b[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}
