#include <bits/stdc++.h>
using namespace std;
int sum[200010], lazy[200010], n, q, i, size1[200010], a[200010];
int gi() {
  int x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
void down(int x) {
  sum[x << 1] += lazy[x] * size1[x << 1];
  sum[x << 1 | 1] += lazy[x] * size1[x << 1 | 1];
  lazy[x << 1] += lazy[x], lazy[x << 1 | 1] += lazy[x], lazy[x] = 0;
}
void build(int x, int l, int r) {
  size1[x] = (r - l + 1);
  if (l == r) {
    sum[x] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(x << 1, l, mid), build(x << 1 | 1, mid + 1, r);
  sum[x] = sum[x << 1] + sum[x << 1 | 1];
}
void updata(int x, int l, int r, int xl, int xr, int v) {
  down(x);
  if (xl == l && xr == r) {
    sum[x] += v * size1[x], lazy[x] += v;
    return;
  }
  int mid = (l + r) >> 1;
  if (xr <= mid)
    updata(x << 1, l, mid, xl, xr, v);
  else if (xl > mid)
    updata(x << 1 | 1, mid + 1, r, xl, xr, v);
  else
    updata(x << 1, l, mid, xl, mid, v),
        updata(x << 1 | 1, mid + 1, r, mid + 1, xr, v);
  sum[x] = sum[x << 1] + sum[x << 1 | 1];
}
int query(int x, int l, int r, int xl, int xr) {
  down(x);
  if (xl <= l && r <= xr) return sum[x];
  int mid = (l + r) >> 1;
  if (xr <= mid)
    return query(x << 1, l, mid, xl, xr);
  else if (xl > mid)
    return query(x << 1 | 1, mid + 1, r, xl, xr);
  else
    return query(x << 1, l, mid, xl, mid) +
           query(x << 1 | 1, mid + 1, r, mid + 1, xr);
}
int b1[100001], cnt = 0, index1[100001];
int main() {
  n = gi();
  for (i = 1; i <= n; i++) a[i] = gi();
  q = gi();
  sort(a, a + n + 1);
  for (int i = 1; i <= n; i++) {
    if (a[i] != b1[cnt]) {
      b1[++cnt] = a[i];
      index1[a[i]] = cnt;
    }
  }
  build(1, 1, n);
  for (i = 1; i <= q; i++) {
    int b = gi(), c = gi();
    int l = lower_bound(a, a + n, b) - a;
    int id = b1[index1[b] + 1], r = n + 1;
    if (id) r = lower_bound(a, a + n, b1[index1[b] + 1]) - a;
    if (index1[b]) updata(1, 1, n, l, r - 1, c - b);
    printf("%d\n", query(1, 1, n, 1, n));
    for (int i = l; i < r; i++) a[i] = c;
    cnt = 0;
    sort(a, a + n + 1);
    memset(index1, 0, sizeof(index1));
    memset(b1, 0, sizeof(b1));
    for (int i = 1; i <= n; i++) {
      if (a[i] != b1[cnt]) {
        b1[++cnt] = a[i];
        index1[a[i]] = cnt;
      }
    }
  }
}
