#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
vector<long long> v[10005];
vector<long long> color(10005);
vector<long long> col(10005);
void dfs(long long node, long long pnode, long long colour) {
  color[node] = colour;
  for (long long i = 0; i < v[node].size(); i++) {
    if (v[node][i] != pnode && v[node][i] > node) {
      dfs(v[node][i], pnode, colour);
    }
  }
}
long long sudig(long long n) {
  string s = to_string(n);
  long long ans = 0;
  for (long long i = 0; i < s.length(); i++) {
    ans += s[i] - '0';
  }
  return ans;
}
long long p = 1000000007;
unsigned long long power(unsigned long long x, long long y, long long p) {
  unsigned long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
unsigned long long modInverse(unsigned long long n, long long p) {
  return power(n, p - 2, p);
}
unsigned long long nCrModPFermat(unsigned long long n, long long r,
                                 long long p) {
  if (r == 0) return 1;
  unsigned long long fac[n + 1];
  fac[0] = 1;
  for (long long i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long arr[n];
    for (long long i = 0; i < n; i++) {
      cin >> arr[i];
    }
    long long neg = 0;
    long long pos = 0;
    for (long long i = n - 1; i >= 0; i--) {
      if (arr[i] >= 0) {
        if (neg < 0) {
          neg = min((long long)0, arr[i] + neg);
        }
      } else {
        neg += arr[i];
      }
    }
    cout << abs(neg) << endl;
  }
}
