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