#include <bits/stdc++.h>
using namespace std;
int binary_search(int v[], int x, int N) {
  int stanga = 0, dreapta = N - 1, m;
  while (stanga < dreapta) {
    m = (stanga + dreapta) / 2;
    if (v[m] < x)
      stanga = m + 1;
    else
      dreapta = m;
  }
  if (v[stanga] == x) return stanga;
  return -1;
}
int main() {
  int n, k, v[10000], s = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    s += v[i];
  }
  sort(v, v + n);
  cin >> k;
  for (int i = 0; i < k; i++) {
    int s = 0, bi, ci;
    cin >> bi >> ci;
    if (binary_search(v, bi, n) != -1) {
      int j = binary_search(v, bi, n);
      while (v[j] == bi) {
        s -= v[j];
        v[j] = ci;
        s += v[j];
        j++;
      }
    }
    cout << s << '\n';
  }
}
