#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (int)n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  int q, b, c;
  cin >> q;
  unsigned long sum = 0;
  for (int i = 0; i < (int)n; i++) sum += a[i];
  for (int i = 0; i < (int)q; i++) {
    cin >> b >> c;
    int cnt = count(a.begin(), a.end(), b);
    for (int j = 0; j < (int)n; j++) {
      if (!cnt) break;
      if (a[j] == b) {
        sum += c - a[j];
        a[j] = c;
        cnt--;
      }
    }
    cout << sum << endl;
  }
}
