#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> item(10e5 + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    item[a[i]]++;
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q), s(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 i = 0; i < q; i++) {
    sum += (c[i] - b[i]) * item[b[i]];
    item[c[i]] += item[b[i]];
    cout << sum << endl;
  }
  return 0;
}
