#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sort(a.begin(), a.end());
    auto lower = lower_bound(a.begin(), a.end(), b);
    auto upper = upper_bound(a.begin(), a.end(), b);
    for (; lower < upper; lower++) {
      *lower = c;
      sum -= b;
      sum += c;
    }
    cout << sum << '\n';
  }
  return 0;
}
