#include <bits/stdc++.h>
using namespace std;
long long int n, m, sum;
map<pair<long long int, long long int>, long long int> query;
map<long long int, long long int> no;
long long int powmod(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    long long int val;
    cin >> val;
    sum += val;
    no[i] = val;
  }
  cin >> m;
  while (m--) {
    long long int s, t, u;
    cin >> s >> t >> u;
    if (query.find(make_pair(s, t)) != query.end()) {
      long long int temp = query[make_pair(s, t)];
      query.erase(make_pair(s, t));
      if (no[temp] >= 0) sum++;
      no[temp]++;
      if (u != 0) {
        query[make_pair(s, t)] = u;
        if (no[u] > 0) sum--;
        no[u]--;
      }
    } else {
      if (u != 0) {
        query[make_pair(s, t)] = u;
        if (no[u] > 0) sum--;
        no[u]--;
      }
    }
    cout << sum << "\n";
  }
}
