#include <bits/stdc++.h>
int sort(long long int i, long long int j, long long a[]) {
  if (a[i] > a[j]) {
    int tmp = a[i];
    a[i] = a[j];
    a[j] = tmp;
  }
}
int main(void) {
  long long int n, q, a[100000], b[100000], c[10000], i, j, k,
      sum[100000] = {0}, tmp;
  scanf("%lld", &n);
  for (i = 0; i < n; i++) scanf("%lld", &a[i]);
  for (i = 0; i < n; ++i) {
    for (j = i + 1; j < n; ++j) {
      sort(i, j, a);
    }
  }
  scanf("%lld", &q);
  for (i = 0; i < q; i++) {
    scanf("%lld%lld", &b[i], &c[i]);
    for (j = 0; j < n; j++) {
      if (a[j] == b[i]) a[j] = c[i];
    }
    for (k = 0; k < n; k++) sum[i] += a[k];
  }
  for (i = 0; i < q; i++) printf("%lld\n", sum[i]);
  return 0;
}
