#include <bits/stdc++.h>
using namespace std;
long long ar[2000000];
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, sm = 0, ans = 0;
    cin >> n;
    for (long long i = 0; i < n; i++) cin >> ar[i];
    for (long long i = 0; i < n; i++) {
      long long x = ar[i];
      if (x >= 0) {
        sm += ar[i];
        ar[i] = 0;
      } else {
        if (sm > 0) {
          if (x + sm > 0) {
            ar[i] = 0;
            sm += x;
          } else {
            ar[i] = x + sm;
            sm = 0;
          }
        }
      }
    }
    for (long long i = 0; i < n; i++)
      if (ar[i] < 0) ans += abs(ar[i]);
    cout << ans << endl;
  }
}
