#include <bits/stdc++.h>
using namespace std;
long long int arr[200200];
long long int now[200200];
map<pair<long long int, long long int>, int> mp;
int main() {
  int n, i, j, k, x, y, ans, temp, curr, m;
  int tc;
  cin >> n;
  long long int chaeng = 0;
  for (i = 1; i <= n; i++) {
    scanf("%lld", &arr[i]);
    chaeng += arr[i];
  }
  int q;
  cin >> q;
  while (q--) {
    long long int a, b, c;
    cin >> a >> b >> c;
    if (mp[{a, b}] > 0) {
      long long int last = mp[{a, b}];
      mp[{a, b}] = 0;
      if (last != 0) {
        now[last]--;
        if (now[last] < arr[last]) chaeng++;
      }
    }
    if (c != 0) {
      mp[{a, b}] = c;
      now[c]++;
      if (now[c] <= arr[c]) {
        chaeng--;
      }
    }
    cout << chaeng << endl;
  }
  return 0;
}
