#include <bits/stdc++.h>
struct bctyp {
  int a;
  int c;
};
int asbc(const void *x, const void *y) {
  return (*(struct bctyp *)x).a - (*(struct bctyp *)y).a;
}
int n;
struct bctyp ac[100000];
int search(int x) {
  int l, r, m;
  l = 0;
  r = n - 1;
  while (l <= r) {
    m = (l + r) / 2;
    if (ac[m].a == x) return m;
    if (ac[m].a < x)
      l = m + 1;
    else
      r = m - 1;
  }
  return -1;
}
int main() {
  int i, j, q, p, b, c, pp, ii;
  long s;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &(ac[i].a));
  qsort(ac, n, sizeof(struct bctyp), asbc);
  ac[0].c = 1;
  for (i = 1, j = 0; i < n; i++)
    if (ac[i].a == ac[j].a)
      ac[j].c++;
    else {
      j++;
      ac[j] = ac[i];
      ac[j].c = 1;
    }
  n = j + 1;
  s = 0;
  for (i = 0; i < n; i++) s = s + ac[i].a * ac[i].c;
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d %d", &b, &c);
    p = search(b);
    if (p < 0) {
      printf("%ld\n", s);
      continue;
    }
    pp = search(c);
    s = s + (c - ac[p].a) * ac[p].c;
    if (pp < 0) {
      ac[p].a = c;
    } else {
      ac[pp].c += ac[p].c;
      n--;
      ac[p] = ac[n];
    }
    qsort(ac, n, sizeof(struct bctyp), asbc);
    printf("%ld\n", s);
  }
  return 0;
}
