#include <bits/stdc++.h>
int compare_ints(const void* a, const void* b) {
  int arg1 = *(const int*)a;
  int arg2 = *(const int*)b;
  if (arg1 < arg2) return -1;
  if (arg1 > arg2) return 1;
  return 0;
}
int main(void) {
  int n;
  int a[100001];
  int q;
  int b[100001];
  int c[100001];
  int i;
  int j;
  long long int s;
  s = 0;
  scanf("%d\n", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s += a[i];
  }
  qsort(a, n, sizeof(int), compare_ints);
  scanf("%d\n", &q);
  for (j = 0; j < q; j++) {
    scanf("%d %d\n", &b[j], &c[j]);
  }
  for (j = 0; j < q; j++) {
    for (i = 0; i < n; i++) {
      if (a[i] > b[j]) {
        break;
      }
      if (a[i] == b[j]) {
        s = s + c[j] - a[i];
        a[i] = c[j];
        while (a[i + 1] == b[j]) {
          s = s + c[j] - a[i + 1];
          a[i + 1] = c[j];
          i++;
        }
      }
      qsort(a, n, sizeof(int), compare_ints);
    }
    printf("%lld\n", s);
  }
  return (0);
}
