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