#include <bits/stdc++.h>
using namespace std;
long long sum(long long ara[], long long size) {
  long long s = 0;
  for (int i = 0; i < size; i++) {
    s += ara[i];
  }
  return s;
}
int main() {
  long long n, q, b, c;
  cin >> n;
  long long s[n];
  for (long long i = 0; i < n; i++) {
    long long ai;
    cin >> ai;
    s[i] = ai;
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    for (int j = 0; j < n; j++) {
      if (s[j] == b) {
        s[j] = c;
      }
    }
    cout << sum(s, n);
  }
  return 0;
}
