#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long int INF = 9e18 + 2e17;
const int inf = 2e9;
const int N = 1e3 + 22;
const double eps = 1e-10;
const double PI = 3.14159265;
void solve() {
  int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long int p = 0, neg = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] == 0) continue;
    if (a[i] > 0) {
      if (a[i] > neg) {
        p += a[i] - neg;
        neg = 0;
      } else {
        neg -= a[i];
      }
    } else {
      neg += abs(a[i]);
    }
  }
  cout << max(p, neg);
  cout << '\n';
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
