#include <bits/stdc++.h>
using namespace std;
char _buf[100000], *_op(_buf), *_ed(_buf);
inline int getint() {
  register int _s = 0, _f = 1;
  register char _ch =
      (_op == _ed &&
               (_ed = (_op = _buf) + fread(_buf, 1, 100000, stdin), _op == _ed)
           ? EOF
           : *_op++);
  while (!('0' <= _ch && _ch <= '9'))
    (_ch == '-') && (_f = -1),
        _ch =
            (_op == _ed && (_ed = (_op = _buf) + fread(_buf, 1, 100000, stdin),
                            _op == _ed)
                 ? EOF
                 : *_op++);
  while (('0' <= _ch && _ch <= '9'))
    _s = _s * 10 + _ch - 48,
    _ch = (_op == _ed && (_ed = (_op = _buf) + fread(_buf, 1, 100000, stdin),
                          _op == _ed)
               ? EOF
               : *_op++);
  return _s * _f;
}
inline int max(const int& x, const int& y) { return x > y ? x : y; }
const int N = 1e6 + 1;
long long int ans;
map<pair<int, int>, int> mp;
int n, m, s, t, u, a[N];
int main() {
  n = getint();
  for (register int i = 1; i <= n; i++) a[i] = getint(), ans += a[i];
  for (m = getint(); m--;) {
    s = getint(), t = getint();
    if (u = mp[{s, t}])
      ans -= max(0, a[u]++), ans += max(0, a[u]), mp[{s, t}] = 0;
    if (u = getint())
      ans -= max(0, a[u]--), ans += max(0, a[u]), mp[{s, t}] = u;
    cout << ans << '\n';
  }
  return 0;
}
