#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int arr[N];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    long long cost = 0;
    long long neg = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (arr[i] <= 0) {
        neg += arr[i];
      } else {
        int val = arr[i];
        if (abs(neg) >= val) {
          neg = neg + val;
          val = 0;
        } else {
          val = val + neg;
          neg = 0;
        }
        cost += val;
        val = 0;
      }
    }
    if (cost < 0) {
      throw runtime_error("Overflow");
    }
    cout << cost << endl;
  }
  return 0;
}
