#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 3;
int n, b[MAXN], head, tail;
long long a[MAXN];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    head = 0, tail = 0;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
      if (a[i] > 0) {
        b[++tail] = i;
      } else if (a[i] < 0) {
        while (head < tail && a[i] != 0) {
          if (a[b[tail]] >= fabs(a[i]))
            a[b[tail]] -= fabs(a[i]), a[i] = 0;
          else {
            a[i] += a[b[tail]], a[b[tail]] = 0, tail--;
          }
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      if (a[i] > 0) ans += a[i];
    }
    printf("%lld\n", ans);
  }
  return 0;
}
