#include <bits/stdc++.h>
long long gcd(long long a, long long b) {
  if (a == 0 || b == 0 || a == b) return a == b ? a : (a > 0 ? a : b);
  return a > b ? gcd(b, a % b) : gcd(a, b % a);
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int z = 0; z < (t); z++) {
    int n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < (n); i++) cin >> a[i];
    long long sp = 0, sn = 0;
    for (int i = 0; i < (n); i++) {
      if (a[i] > 0)
        sp += a[i];
      else {
        if (sp > 0) {
          if (abs(a[i]) > sp) {
            a[i] += sp;
            sp = 0;
            sn += a[i];
          } else {
            sp += a[i];
            a[i] = 0;
          }
        } else
          sn += a[i];
      }
    }
    cout << -sn << endl;
  }
  return 0;
}
