#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) {
  return os << '(' << pai.first << ' ' << pai.second << ')';
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
  os << '[';
  for (auto p : v) os << p << ",";
  os << "]";
  return os;
}
template <typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
  os << "{";
  for (auto p : v) os << p << ",";
  os << "}";
  return os;
}
template <typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
  os << "{";
  for (auto p : v) os << p << ",";
  os << "}";
  return os;
}
ostream &operator<<(ostream &os, tuple<int, int, int> t) {
  os << "<" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ">";
  return os;
}
template <typename T>
void get_max(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void get_min(T &a, T b) {
  a = min(a, b);
}
int N, M;
int A[200001];
int C[200001];
long long res;
void inc(int idx) {
  if (idx == 0) return;
  if (C[idx]++ < A[idx]) res--;
}
void dec(int idx) {
  if (idx == 0) return;
  if (C[idx]-- <= A[idx]) res++;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  for (int i = (1), _i = (N); i <= _i; i++) cin >> A[i];
  res = accumulate(A + 1, A + N + 1, 0ll);
  cin >> M;
  map<pair<int, int>, int> s;
  while (M--) {
    int a, b, x;
    cin >> a >> b >> x;
    if (s.find({a, b}) != s.end()) {
      dec(s[{a, b}]);
    }
    s[{a, b}] = x;
    inc(x);
    cout << res << '\n';
  }
}
