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