#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long sum = 0;
  for (long long i = n - 1; i >= 0; i--) {
    sum += a[i];
    if (sum > 0) {
      a[i] = sum;
      sum = 0;
    } else
      a[i] = 0;
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] > 0) ans += a[i];
  }
  cout << ans << endl;
}
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
}
