#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]\n";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << ", " << P.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, set<T> second) {
  os << "{ ";
  for (auto s : second) os << s << " ";
  return os << "}\n";
}
template <class L, class R>
ostream& operator<<(ostream& os, map<L, R> M) {
  os << "{ ";
  for (auto m : M) os << "(" << m.first << ":" << m.second << ") ";
  return os << "}\n";
}
void solve() {
  long long n, cur = 0;
  cin >> n;
  vector<long long> a(n);
  for (__typeof(n) i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] > 0)
      cur += a[i];
    else {
      if (cur + a[i] >= 0) {
        cur += a[i];
        a[i] = 0;
      } else {
        a[i] += cur;
        cur = 0;
      }
    }
  }
  cout << cur << "\n";
}
int32_t main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 0;
  if (!t) cin >> t;
  while (t--) solve();
}
