#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const long long dif = 1e10;
map<long long, int> mp;
int a[maxn];
long long add[maxn];
int main() {
  int n;
  scanf("%d", &n);
  long long sum = 0, jy = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  int q;
  scanf("%d", &q);
  int s, u, t;
  while (q--) {
    scanf("%d%d%d", &s, &t, &u);
    long long tmp = s * dif + t;
    if (mp[tmp]) {
      int z = mp[tmp];
      add[z]--;
      mp[tmp] = 0;
      if (add[z] < a[z]) {
        jy--;
      }
    }
    if (u == 0) {
    } else {
      mp[tmp] = u;
      add[u]++;
      if (add[u] <= a[u]) {
        jy++;
      }
    }
    printf("%I64d\n", sum - jy);
  }
}
