#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a, p = 0, sol = 0;
    for (long long int i = 0; i < n; i++) {
      cin >> a;
      if (a > 0) {
        p += a;
      } else {
        a = a * -1;
        if (p > a) {
          p = p - a;
        } else {
          sol = sol + (a - p);
          p = 0;
        }
      }
    }
    cout << sol << "\n";
  }
}
