#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
map<pair<int, int>, int> M;
vector<long long> V;
int n, q;
int a[N], b[N];
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    ans += a[i];
  }
  scanf("%d", &q);
  int s, t, u;
  while (q--) {
    scanf("%d%d%d", &s, &t, &u);
    pair<int, int> tmp = (pair<int, int>){s, t};
    if (!M.count(tmp) || M[tmp] == 0) {
      M[tmp] = u;
      b[u]++;
      if (b[u] <= a[u]) ans--;
    } else {
      int v = M[tmp];
      b[v]--;
      if (b[v] < a[v]) ans++;
      M[tmp] = u;
      if (u) {
        b[u]++;
        if (b[u] <= a[u]) ans--;
      }
    }
    V.push_back(ans);
  }
  int j = V.size();
  for (int i = 0; i < j; ++i) {
    printf("%lld\n", V[i]);
  }
  return 0;
}
