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