#include <bits/stdc++.h>
using namespace std;
int n, b, c, q, a[100009];
long long sum;
int binsA(int w) {
  int l = 0, r = n - 1;
  if (w < a[l]) return l - 1;
  if (w > a[r]) return r + 1;
  while (r > l) {
    int mid = (l + r) / 2;
    if (a[mid] >= w) {
      r = mid;
    } else
      l = mid + 1;
  }
  return l;
}
int binsB(int w) {
  int l = 0, r = n - 1;
  if (w < a[l]) return l - 1;
  if (w > a[r]) return r + 1;
  while (r > l) {
    int mid = (l + r) / 2;
    if (a[mid] > w) {
      r = mid;
    } else
      l = mid + 1;
  }
  return l;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    int o = binsA(b), p = binsB(b);
    if (o == -1 || o == n || a[o] != b) {
      cout << sum << endl;
      continue;
    }
    for (int j = o; j < p; j++) {
      sum += c - b;
      a[j] = c;
    }
    cout << sum << endl;
  }
  return 0;
}
