#include <bits/stdc++.h>
using namespace std;
int long long a[200005], b[200005];
vector<int> v;
int main() {
  int n, t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    int long long neg = 0, ans = 0;
    for (int i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
    }
    for (int i = n - 1; i >= 0; i--) {
      neg += a[i];
      if (a[i] > 0) {
        if (neg > 0) {
          ans += neg;
          neg = 0;
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
