#include <bits/stdc++.h>
using namespace std;
const int n = 2e5 + 5;
int N, K, Q;
long long T[n], A[n];
map<int, int> M[n];
long long IC[n];
long long cost(int i) { return max(0ll, A[i] - IC[i]); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  long long c = 0;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    c += A[i];
  }
  cin >> Q;
  for (int q = 0; q < Q; ++q) {
    int s, t, u;
    cin >> s >> t >> u;
    s--;
    u--;
    if (M[s].count(t) == 1 && M[s][t] != -1) {
      int uOld = M[s][t];
      c -= cost(uOld);
      IC[uOld]--;
      c += cost(uOld);
    }
    M[s][t] = u;
    if (u != -1) {
      c -= cost(u);
      IC[u]++;
      c += cost(u);
    }
    cout << c << "\n";
  }
  return 0;
}
