#include <bits/stdc++.h>
using namespace std;
long long mi[300007], a[300007], ans;
map<long long, long long> mp[300005];
int main() {
  long long n, i, q, x, y, z;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    ans += a[i];
  }
  scanf("%lld", &q);
  while (q--) {
    long long j = 0;
    scanf("%lld%lld%lld", &x, &y, &z);
    if (mp[x][y]) {
      mi[mp[x][y]]--;
      if (a[mp[x][y]] > mi[mp[x][y]]) j = 1;
    }
    ans += j;
    mp[x][y] = z;
    mi[z]++;
    if (mi[z] <= a[z]) ans--;
    cout << ans << endl;
  }
  return 0;
}
