#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long ar[n];
    for (long long i = 0; i < n; i++) cin >> ar[i];
    long long ans = 0;
    long long incr = 0;
    for (long long i = 0; i < n; i++) {
      if (ar[i] < 0) {
        long long temp = incr;
        incr -= min(incr, abs(ar[i]));
        ar[i] += min(temp, abs(ar[i]));
        if (ar[i] < 0) {
          ans += abs(ar[i]);
        }
      } else {
        incr += ar[i];
        ar[i] = 0;
      }
    }
    cout << ans << "\n";
  }
}
