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