#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
long long a[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t, n, Max, flag;
  cin >> t;
  while (t--) {
    cin >> n;
    Max = 0, flag = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    long long ans = 0, zeng = 0;
    for (long long i = 0; i < n; i++) {
      if (a[i] < 0) {
        if (zeng + a[i] == 0)
          zeng = 0;
        else if (zeng + a[i] > 0)
          zeng += a[i];
        else if (zeng + a[i] < 0)
          ans += zeng + a[i], zeng = 0;
      } else
        zeng += a[i];
    }
    cout << abs(ans) << endl;
  }
  return 0;
}
