#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
inline long long read() {
  long long x = 0, neg = 1;
  char op = getchar();
  while (!isdigit(op)) {
    if (op == '-') neg = -1;
    op = getchar();
  }
  while (isdigit(op)) {
    x = 10 * x + op - '0';
    op = getchar();
  }
  return neg * x;
}
inline void print(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}
const long long maxn = 1e5 + 10;
long long n, a[maxn];
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (long long i = 1; i <= n; i++) cin >> a[i];
    long long ans = 0, all = 0;
    for (long long i = n; i >= 1; i--) {
      if (a[i] > 0) {
        all -= a[i];
        if (all < 0) ans += -all, all = 0;
      } else
        all += abs(a[i]);
    }
    cout << ans << '\n';
  }
  return 0;
}
