#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long int> vec;
    for (int i = 0; i < n; ++i) {
      long long int temp;
      cin >> temp;
      vec.push_back(temp);
    }
    long long int total = 0;
    for (int i = 0; i < n; ++i)
      if (vec[i] > 0) total += vec[i];
    long long int sum = 0, ans = 0, net = 0;
    for (int i = 0; i < n; ++i) {
      if (vec[i] > 0)
        sum += vec[i];
      else if (i != 0 && vec[i] < 0) {
        ans = min(sum, abs(vec[i]));
        sum -= ans;
        net += ans;
      }
    }
    cout << total - net << endl;
    vec.clear();
  }
  return 0;
}
