#include <bits/stdc++.h>
using namespace std;
const int n = 1e7;
bool arrPrime[n + 1];
vector<long long> vecPrime;
void isPrime() {
  memset(arrPrime, true, sizeof(arrPrime));
  arrPrime[0] = arrPrime[1] = false;
  int limit = sqrt(n);
  vecPrime.push_back(2);
  for (int i = 4; i <= n; i += 2) arrPrime[i] = false;
  for (int i = 3; i <= n; i += 2) {
    if (arrPrime[i]) {
      vecPrime.push_back(i);
      if (i <= limit) {
        for (long long j = i * i; j <= n; j += (2 * i)) arrPrime[j] = false;
      }
    }
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    vector<int> vec, pos;
    int num;
    for (int i = 0; i <= n - 1; i++) {
      scanf("%d", &num);
      vec.push_back(num);
    }
    if (n == 1)
      printf("0\n");
    else {
      long long curr = 0, count = 0;
      for (int i = 0; i <= n - 1; i++) {
        curr += vec[i];
        if (curr < 0) {
          count += curr;
          curr = 0;
        }
      }
      printf("%lld\n", abs(count));
    }
  }
}
