#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigMod(T p, T e, T M) {
  T ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T modInverse(T a, T M) {
  return bigMod(a, M - 2, M);
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n;
int par[100005];
int sz[100005];
int findPar(int v) {
  if (par[v] == v) return v;
  return par[v] = findPar(par[v]);
}
void join(int p, int q) {
  if (sz[q] >= sz[p]) {
    par[p] = q;
    sz[q] += sz[p];
  } else {
    par[q] = p;
    sz[p] += sz[q];
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    long long int sum = 0;
    for (int i = 0; i < n; i++) {
      if (arr[i] > 0)
        sum += arr[i];
      else if (arr[i] < 0) {
        long long int g = abs(arr[i]);
        long long int mn = min(g, sum);
        sum -= mn;
        arr[i] += mn;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
