#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long n, a[N], q, s, t, u, sum;
map<pair<long long, long long>, int> check;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  cin >> q;
  while (q--) {
    cin >> s >> t >> u;
    if (check[{s, t}] != 0) {
      int tmp = check[{s, t}];
      sum -= max(0LL, a[tmp]);
      a[tmp]++;
      sum += max(0LL, a[tmp]);
      check[{s, t}] = 0;
    }
    if (u != 0) {
      sum -= max(0LL, a[u]);
      a[u]--;
      sum += max(0LL, a[u]);
      check[{s, t}] = u;
    }
    cout << sum << "\n";
  }
}
