#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
const int N = 2e5 + 1;
int n, a[N], add[N];
long long ans = 0;
map<pair<int, int>, int> magic;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ans += a[i];
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int s, t, u;
    cin >> s >> t >> u;
    int pre = magic[pair<int, int>(s, t)];
    if (pre != u) {
      if (pre > 0) {
        ans += min(add[pre], a[pre]);
        add[pre]--;
        ans -= min(add[pre], a[pre]);
      }
      if (u > 0) {
        ans += min(add[u], a[u]);
        add[u]++;
        ans -= min(add[u], a[u]);
      }
      magic[pair<int, int>(s, t)] = u;
    }
    cout << ans << '\n';
  }
  return 0;
}
