#include <bits/stdc++.h>
using namespace std;
long long t, n, a[100001], ans = 0, sum = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    ans = 0, sum = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
      if (a[i] >= 0)
        sum += a[i];
      else {
        if (sum + a[i] >= 0)
          sum += a[i];
        else {
          ans += abs(a[i]) - sum;
          sum = 0;
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
