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