#include <bits/stdc++.h>
using namespace std;
const bool DBG = 1;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(15);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  long long total = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    total += a[i];
  }
  int q;
  cin >> q;
  vector<map<int, int>> ms(n + 1);
  for (int qi = 0; qi < q; qi++) {
    int s, t, u;
    cin >> s >> t >> u;
    if (ms[s][t] != 0) {
      int u2 = ms[s][t];
      total -= max(a[u2], 0);
      a[u2] += 1;
      total += max(a[u2], 0);
    }
    total -= max(a[u], 0);
    a[u] -= 1;
    total += max(a[u], 0);
    ms[s][t] = u;
    cout << total << endl;
  }
  return 0;
}
