#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e5 + 7;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int x, y;
    cin >> x >> y;
    sort(a.begin(), a.end());
    int l = 0, h = n - 1;
    int ans = 0;
    while (l <= h) {
      int m = l + (h - l) / 2;
      if (a[m] == x) {
        ans = m;
        h = m - 1;
      } else if (a[m] > x) {
        h = m - 1;
      } else {
        l = m + 1;
      }
    }
    while (ans < n && a[ans] == x) {
      sum -= x;
      sum += y;
      a[ans] = y;
      ans++;
    }
    cout << sum << "\n";
  }
  return 0;
}
