#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1.0);
const long long MAX = 9000000000000000000;
const long long MIN = -9000000000000000000;
const long double DMAX = 4500;
const long double DMIN = -4500;
const long long MOD = 1000000007;
template <typename T>
void fin(T a) {
  cout << a << endl;
  exit(0);
}
void Main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < (n); ++i) cin >> a[i];
  sort(a.begin(), a.end());
  long long q;
  cin >> q;
  vector<long long> b(q), c(q);
  for (long long i = 0; i < (q); ++i) cin >> b[i] >> c[i];
  long long ans = 0;
  for (long long i = 0; i < (n); ++i) {
    ans += a[i];
  }
  for (long long i = 0; i < (q); ++i) {
    long long s = 0;
    for (long long j = 0; j < n; j++) {
      if (a[j] == b[i]) {
        s++;
        a[j] = c[i];
        ans += c[i];
        ans -= b[i];
      } else if (s != 0)
        break;
    }
    cout << ans << endl;
    sort(a.begin(), a.end());
  }
}
int main() {
  cout << fixed << setprecision(20);
  Main();
  return 0;
}
