#include <bits/stdc++.h>
int main(void) {
  int n;
  scanf("%d", &n);
  int a[n];
  int i;
  long ans = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    ans += a[i];
  }
  int q;
  scanf("%d", &q);
  int b[q], c[q];
  for (i = 0; i < q; i++) {
    scanf("%d %d", &b[i], &c[i]);
  }
  int count = 0, j;
  for (j = 0; j < q; j++) {
    count = 0;
    for (i = 0; i < n; i++) {
      if (a[i] == b[j]) {
        a[i] = c[j];
        ans += (c[j] - b[j]);
      }
    }
    printf("%ld\n", ans);
  }
  return 0;
}
