#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long int res = 0;
  long long int pos = 0;
  for (long long int i = 0; i < n; i++) {
    if (a[i] == 0) continue;
    if (a[i] > 0)
      pos += a[i];
    else {
      pos += a[i];
      if (pos < 0) {
        res += pos;
        pos = 0;
      }
    }
  }
  cout << abs(res) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) solve();
}
