#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<long long int> v(n, 0);
    for (int i = 0; i < n; i++) cin >> v[i];
    vector<long long int> arr;
    long long int sum = 0;
    for (int i = 0; i < n; i++) {
      sum = sum + v[i];
      if (sum < 0) {
        arr.push_back(sum);
        sum = 0;
      }
    }
    sum = 0;
    for (int i = 0; i < (int)arr.size(); i++) {
      if (arr[i] < 0) sum = sum + arr[i];
    }
    cout << abs(sum) << endl;
  }
  return 0;
}
