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