#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long p = 0;
    long long b[n];
    for (long long i = 0; i < n; i++) {
      if (a[i] >= 0)
        p += a[i];
      else {
        b[i] = p;
      }
    }
    long long carry = 0;
    for (long long i = 0; i < n; i++) {
      if (a[i] < 0) {
        if (abs(a[i]) <= carry) {
          carry -= abs(a[i]);
          a[i] = 0;
        } else {
          a[i] = -(abs(a[i]) - carry);
          carry = 0;
        }
      } else {
        carry += a[i];
      }
    }
    long long c = 0;
    for (long long i = 0; i < n; i++) {
      if (a[i] < 0) c += a[i];
    }
    cout << abs(c) << '\n';
  }
  return 0;
}
