#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int 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 ans = 0;
    long long s = 0;
    for (long long i = n - 1; i >= 0; i--) {
      if (a[i] < 0)
        s += a[i];
      else if (a[i] > 0) {
        long long m = min(abs(s), a[i]);
        s += m;
      }
    }
    cout << abs(s) << endl;
  }
}
