#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    long long int SUM_P = 0;
    long long int SUM_N = 0;
    for (int i = 0; i < n; i++) {
      if (v[i] < 0) {
        if (SUM_P) {
          long long int get = min(SUM_P, -v[i]);
          SUM_P -= get;
          SUM_N += abs(v[i]) - get;
        }
      } else
        SUM_P += v[i];
    }
    cout << max(SUM_P, SUM_N) << endl;
  }
}
