#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  int q;
  cin >> q;
  long long int sum = 0;
  sum = accumulate(v.begin(), v.end(), 0);
  while (q--) {
    int bi, ci;
    cin >> bi >> ci;
    for (int i = 0; i < n; i++) {
      if (v[i] == bi) {
        int z = ci - v[i];
        sum += z;
        v[i] = ci;
      }
    }
    cout << sum << endl;
  }
}
