#include <bits/stdc++.h>
using namespace std;
long long ans, mx, sum, mn = 1e8, cnt;
long long binarySearch(long long arr[], long long l, long long r, long long x) {
  while (l <= r) {
    long long m = l + (r - l) / 2;
    if (arr[m] == x) return m;
    if (arr[m] < x)
      l = m + 1;
    else
      r = m - 1;
  }
  return -1;
}
int main() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long q;
  cin >> q;
  long long b, c;
  for (long long i = 0; i < q; i++) {
    cin >> b >> c;
    for (long long j = 0; j <= 100000; j++) {
      long long k = binarySearch(a, 0, n - 1, b);
      if (k != -1) {
        sum -= b;
        sum += c;
        a[k] = c;
        sort(a, a + n);
      } else {
        cout << sum << endl;
        break;
      }
    }
  }
}
