#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, sum = 0, cost = 0;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; ++i) cin >> v[i];
  for (auto el : v) {
    sum += el;
    if (sum < 0) {
      cost += abs(sum);
      sum = 0;
    }
  }
  cout << cost << "\n";
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int tests;
  cin >> tests;
  for (; tests; --tests) solve();
}
