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