#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void swap(long long int &a, long long int &b) {
  long long int temp = a;
  a = b;
  b = temp;
}
long long int fast(long long int a, long long int m) {
  if (m == 1) return a % 998244353;
  if (m == 0) return 1;
  long long int temp = fast(a, m / 2);
  temp = (temp * temp) % 998244353;
  if (m % 2) return (temp * a) % 998244353;
  return temp;
}
void pre() {}
void solve() {
  long long int n;
  cin >> n;
  long long int a[200009], sum = 0;
  for (long long int i = 0; i < (n); ++i) cin >> a[i], sum += a[i];
  long long int q;
  cin >> q;
  map<pair<long long int, long long int>, long long int> temp;
  long long int cnt[200009];
  memset(cnt, 0, sizeof(cnt));
  while (q--) {
    long long int s, t, u;
    cin >> s >> t >> u;
    s--, u--;
    if (temp.find({s, t}) != temp.end()) {
      long long int v = temp[{s, t}];
      sum += min(a[v], cnt[v]);
      cnt[v]--;
      temp.erase({s, t});
      sum -= min(a[v], cnt[v]);
    }
    if (u != -1) {
      sum += min(a[u], cnt[u]);
      cnt[u]++;
      temp[{s, t}] = u;
      sum -= min(a[u], cnt[u]);
    }
    cout << sum << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) solve();
  return 0;
}
