#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    auto x = lower_bound(a.begin(), a.end(), b);
    int y = *x;
    if (y == b) {
      while (a[x - a.begin()] == b) {
        a[x - a.begin()] = c;
        x++;
        ans -= b;
        ans += c;
      }
      sort(a.begin(), a.end());
    }
    cout << ans << endl;
  }
  return 0;
}
