#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 20;
map<int, int> mp[maxn];
int cnt[maxn], a[maxn];
long long sum;
void handle(int s, int t, int u, int val) {
  sum -= max(0, a[u] - cnt[u]);
  cnt[u] += val;
  sum += max(0, a[u] - cnt[u]);
  if (val == -1)
    mp[s].erase(t);
  else
    mp[s][t] = u;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];
  int q;
  cin >> q;
  while (q--) {
    int s, t, u;
    cin >> s >> t >> u;
    s--, u--;
    if (mp[s].count(t)) handle(s, t, mp[s][t], -1);
    if (u >= 0) handle(s, t, u, 1);
    cout << sum << endl;
  }
}
