#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<long long> vec(n);
  for (long long i = 0; i < n; ++i) {
    cin >> vec[i];
  }
  long long sum = accumulate(vec.begin(), vec.end(), 0);
  long long q;
  cin >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    for (long long i = 0; i < n; ++i) {
      if (vec[i] == x) {
        vec[i] = y;
        sum += y - x;
      }
    }
    cout << sum << endl;
  }
}
int main() {
  int q;
  q = 1;
  while (q--) solve();
  return 0;
}
