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