#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, Q, t, u, ANS = 0;
  vector<pair<long long, long long>> A;
  cin >> N;
  for (int i = 0; i < (int)N; ++i) {
    cin >> t;
    ANS = ANS + t;
    A.push_back(make_pair(t, 1));
  }
  cin >> Q;
  for (int i = 0; i < (int)Q; ++i) {
    cin >> t >> u;
    for (int j = 0; j < (int)A.size(); ++j) {
      if (A[j].first == t) {
        ANS = ANS + A[j].second * (u - t);
        A[j].first = u;
      }
    }
    cout << ANS << endl;
  }
}
