#include <bits/stdc++.h>
int main() {
  long long int n, q, i, j, a[100002], b, c, sum = 0;
  scanf("%lld", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  scanf("%lld", &q);
  for (i = 0; i < q; i++) {
    sum = 0;
    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);
  }
  return 0;
}
