#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)1e5 + 5;
long long a[N];
inline void solve() {
  long long n;
  cin >> n;
  queue<pair<long long, long long> > negative, positive;
  long long pos_sum = 0;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (a[i] == 0) {
      continue;
    }
    if (a[i] > 0) {
      pos_sum += a[i];
      positive.push({i, a[i]});
    } else {
      negative.push({i, a[i]});
    }
  }
  while (!positive.empty()) {
    long long p = positive.front().first;
    long long x = positive.front().second;
    while (!negative.empty() && negative.front().first < p) {
      negative.pop();
    }
    if (negative.empty()) {
      break;
    }
    long long relax = min(x, -negative.front().second);
    positive.front().second -= relax;
    pos_sum -= relax;
    if (positive.front().second == 0) {
      positive.pop();
    }
    if (relax >= -negative.front().second) {
      negative.pop();
    } else {
      negative.front().second += relax;
    }
  }
  cout << pos_sum << endl;
}
signed main() {
  long long Q;
  cin >> Q;
  while (Q--) {
    solve();
  }
}
