#include <bits/stdc++.h>
using namespace std;
const long long N = 1000000000000002;
long long sum(long long a[], long long sz) {
  long long s = 0;
  for (long long i = 0; i < sz; i++) s += a[i];
  return s;
}
signed main() {
  long long n;
  scanf("%lld", &n);
  long long a[n];
  for (long long i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  long long q;
  scanf("%lld", &q);
  while (q--) {
    long long b, c;
    scanf("%lld %lld", &b, &c);
    for (long long i = 0; i < n; i++) {
      if (a[i] == b) a[i] = c;
    }
    printf("%d\n", sum(a, n));
  }
}
