#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> a;
void solve() {
  cin >> n;
  a.resize(n);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long ans = 0;
  for (long long i = 0; i < n - 1; ++i) {
    if (a[i] >= 0) {
      a[i + 1] += a[i];
      a[i] = 0;
    } else {
      a[n - 1] += a[i];
      ans -= a[i];
      a[i] = 0;
    }
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  for (long long i = 0; i < t; ++i) {
    solve();
    cout << "\n";
  }
  return 0;
}
