#include <bits/stdc++.h>
using namespace std;
void solve() {
  int64_t t;
  cin >> t;
  while (t--) {
    int64_t n;
    cin >> n;
    int64_t a[n], i;
    ;
    for (int64_t i = 0; i < n; i++) cin >> a[i];
    ;
    int64_t ans = -1, val = 0;
    for (int64_t i = n - 1; i >= 0; i--) {
      val += a[i];
      if (val >= 0) {
        ans = max(ans, val);
      }
    }
    cout << ans << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
