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