#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  long long Q;
  cin >> Q;
  vector<long long> b(Q);
  vector<long long> c(Q);
  for (long long i = 0; i < Q; i++) {
    cin >> b.at(i) >> c.at(i);
  }
  for (long long i = 0; i < Q; i++) {
    for (long long j = 0; j < N; j++) {
      if (a.at(j) == b.at(i)) {
        a.at(j) = c.at(i);
      }
    }
    long long x = 0;
    long long sum = 0;
    for (long long k = 0; k < N; k++) {
      x += a.at(k);
      sum = max(x, k);
    }
    cout << sum << endl;
  }
  return 0;
}
