#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, x;
  cin >> t;
  while (t--) {
    cin >> n;
    int x;
    long long sumz = 0, sumf = 0;
    for (int i = 0; i < n; i++) {
      cin >> x;
      if (x > 0)
        sumz += x;
      else {
        if (sumz > abs(x))
          sumz += x;
        else {
          sumz = 0;
          sumf += x + sumz;
        }
      }
    }
    cout << sumz << endl;
  }
  return 0;
}
