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