#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-5;
const double Pi = 3.1415926535897932;
const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1};
const int N = 2e6 + 100;
int cnt[N];
map<int, int> mp[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> cnt[i];
    ans += cnt[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int s, t, u;
    cin >> s >> t >> u;
    if (mp[s][t] != 0) {
      if (cnt[mp[s][t]] >= 0) ans++;
      cnt[mp[s][t]]++;
    }
    mp[s][t] = u;
    if (mp[s][t] != 0) {
      cnt[mp[s][t]]--;
      if (cnt[mp[s][t]] >= 0) ans--;
    }
    cout << ans << '\n';
  }
  return 0;
}
