#include <bits/stdc++.h>
const long long M = 1e9 + 7;
const long long N = 2e5 + 5;
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long z = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > 0) {
      z += a[i];
    } else {
      long long p = min(z, -1 * a[i]);
      a[i] += p;
      z -= p;
      ans -= a[i];
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) solve();
}
