#include <bits/stdc++.h>
using namespace std;
long long int abm(long long int a, long long int b, long long int m) {
  long long int ans = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1) ans = (ans * a) % m;
    a = (a * a) % m;
    b = b / 2;
  }
  return ans % m;
}
long long int ncr(long long int n, long long int r, long long int m) {
  if (r == 0) return 1;
  long long int fac[n + 5];
  fac[0] = 1;
  for (long long int i = (long long int)1; i < (long long int)n + 1; i++) {
    fac[i] = fac[i - 1] * i % m;
  }
  return (((fac[n] * abm(fac[r], m - 2, m)) % m) *
          (abm(fac[n - r], m - 2, m))) %
         m;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int arr[n];
    for (long long int i = (long long int)0; i < (long long int)n; i++)
      cin >> arr[i];
    long long int cntp = 0, ans = 0;
    for (long long int i = (long long int)0; i < (long long int)n; i++) {
      if (arr[i] < 0) {
        if (cntp > (-1 * arr[i]))
          cntp += arr[i];
        else if (cntp == (-1 * arr[i]))
          cntp = 0;
        else {
          ans += (cntp + arr[i]);
          cntp = 0;
        }
      } else if (arr[i] == 0)
        continue;
      else {
        cntp += arr[i];
      }
    }
    cout << -1 * ans << endl;
  }
  return 0;
}
