#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  std::vector<long long> A(n);
  for (long long i = 0; i < n; i++) {
    cin >> A[i];
  }
  long long sm = 0;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (A[i] < 0) {
      if (sm < (-1 * A[i])) {
        ans += ((-1 * A[i]) - sm);
        sm = 0;
      } else {
        sm = sm - (-1 * A[i]);
      }
    } else {
      sm += A[i];
    }
  }
  cout << ans << endl;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  for (long long i = 1; i <= t; i++) {
    solve();
  }
}
