#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t > 0) {
    int n;
    cin >> n;
    vector<int> arr;
    for (int i = 0; i < n; i++) {
      int temp;
      cin >> temp;
      arr.push_back(temp);
    }
    long long int nsum = 0;
    int i = n - 1;
    while (i >= 0) {
      if (arr[i] <= 0) {
        nsum = nsum + arr[i];
      } else {
        nsum = nsum + arr[i];
        if (nsum > 0) nsum = 0;
      }
      i--;
    }
    if (nsum < 0)
      cout << (-1) * (nsum) << endl;
    else
      cout << 0 << endl;
    t--;
  }
  return 0;
}
