#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int book[maxn], n, num[maxn];
long long ans = 0;
map<pair<int, int>, int> mp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = (1); i <= (n); i++) cin >> book[i], ans += book[i];
  int m;
  cin >> m;
  while (m--) {
    int s, t, u;
    cin >> s >> t >> u;
    pair<int, int> now = {s, t};
    auto it = mp.find(now);
    if (it == mp.end()) {
      mp[now] = u;
      ans -= max(0, book[u] - num[u]);
      num[u]++;
      ans += max(0, book[u] - num[u]);
    } else {
      ans -= max(0, book[mp[now]] - num[mp[now]]);
      num[mp[now]]--;
      ans += max(0, book[mp[now]] - num[mp[now]]);
      ans -= max(0, book[u] - num[u]);
      num[u]++;
      ans += max(0, book[u] - num[u]);
      mp[now] = u;
    }
    cout << ans << '\n';
  }
  return 0;
}
