#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    long long int *a = new long long int[n]{0};
    long long int sum = 0;
    long long int mx = INT_MIN;
    long long int pos = -1;
    for (long long int i = 0; i < n; ++i) {
      cin >> a[i];
      if (a[i] > 0) {
        sum += a[i];
      } else if (a[i] < 0 && sum >= 0) {
        long long int x = min(abs(a[i]), sum);
        sum -= x;
        a[i] += x;
      }
    }
    sum = 0;
    for (long long int i = 0; i < n; ++i) {
      if (a[i] < 0) {
        sum += a[i];
      }
    }
    sum *= -1;
    cout << sum << endl;
  }
  return 0;
}
