#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long ans = 0;
    long long sm = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] < 0) {
        ans += max(-(a[i] + sm), 0ll);
        sm += a[i];
        if (sm < 0) {
          sm = 0;
        }
      } else {
        sm += a[i];
      }
    }
    cout << ans << endl;
  }
}
