#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 2e5 + 100;
int N;
long long a[MAXN];
void read() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
}
void solve() {
  read();
  long long mn = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (a[i] < 0) {
      mn += (-a[i]);
    } else {
      mn = max((long long)0, mn - a[i]);
    }
  }
  cout << mn << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
