#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, n, t, sum, sum1;
  cin >> t;
  while (t--) {
    cin >> n;
    long long int a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    sum = 0;
    sum1 = 0;
    for (i = 0; i < n; i++) {
      if (a[i] >= 0)
        sum += a[i];
      else {
        if (sum + a[i] >= 0)
          sum += a[i];
        else {
          a[i] = sum + a[i];
          sum = 0;
          sum1 += a[i];
        }
      }
    }
    cout << sum << endl;
  }
  return 0;
}
