#include <bits/stdc++.h>
using namespace std;
long long n, k, a[200005], p[200005], ans = 0, m;
map<pair<long long, long long>, long long> mp;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[i] = a[i];
    ans += a[i];
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    if (mp[{x, y}] != 0) {
      p[mp[{x, y}]]++;
      if (p[mp[{x, y}]] > 0) ans++;
    }
    mp[{x, y}] = z;
    if (p[z] > 0) ans--;
    p[z]--;
    cout << ans << '\n';
  }
  return 0;
}
