#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, fh = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * fh;
}
const int maxn = 1e5 + 5;
int a[maxn];
void work() {
  int n = read();
  long long ans = 0, sum = 0;
  for (register int i = 1; i <= n; ++i) a[i] = read();
  for (register int i = n; i >= 1; --i) {
    if (a[i] < 0)
      sum += a[i];
    else {
      if (sum + a[i] >= 0)
        sum = 0;
      else
        sum += a[i];
    }
  }
  printf("%lld\n", -sum);
}
int main() {
  int T = read();
  while (T--) {
    work();
  }
  return 0;
}
