#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T biton(T n, T pos) {
  return n((T)1 << pos);
}
template <class T>
inline T bitoff(T n, T pos) {
  return n & ~((T)1 << pos);
}
template <class T>
inline T ison(T n, T pos) {
  return (bool)(n & ((T)1 << pos));
}
template <class T>
inline T gcd(T a, T b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
inline int nxt() {
  int aaa;
  scanf("%d", &aaa);
  return aaa;
}
inline long long lxt() {
  long long aaa;
  scanf("%lld", &aaa);
  return aaa;
}
inline double dxt() {
  double aaa;
  scanf("%lf", &aaa);
  return aaa;
}
inline void vinput(int n, vector<long long>& v) {
  for (long long in, i = 0; i < n; i++) {
    cin >> in;
    v.push_back(in);
  }
}
inline void vout(vector<int> v) {
  for (auto it : v) cout << it << " ";
  cout << endl;
}
int cs = 0;
void solve() {
  int n;
  cin >> n;
  vector<long long> v;
  vinput(n, v);
  deque<long long> pos, neg;
  for (int i = 0; i < n; i++) {
    long long out = v[i];
    if (out > 0)
      pos.push_back(i);
    else if (out < 0)
      neg.push_back(i);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long it = v[i];
    if (it == 0) continue;
    if (it > 0) {
      while (neg.size() && neg.front() <= i) neg.pop_front();
      while (neg.size() && v[neg.front()] == 0) neg.pop_front();
      while (it > 0) {
        assert(neg.size());
        long long mn = min(it, abs(v[neg.front()]));
        it -= mn;
        v[neg.front()] += mn;
        if (v[neg.front()] == 0) neg.pop_front();
      }
    } else {
      while (pos.size() && pos.back() <= i) pos.pop_back();
      while (pos.size() && v[pos.back()] == 0) pos.pop_back();
      it = abs(it);
      while (it > 0) {
        assert(pos.size());
        long long mn = min(it, v[pos.back()]);
        it -= mn;
        v[pos.back()] -= mn;
        ans += mn;
        if (v[pos.back()] == 0) pos.pop_back();
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.setf(ios::fixed);
  cout.precision(2);
  int tc = 1;
  cin >> tc;
  while (tc--) solve();
  return 0;
}
