#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, f, n, m, i, j, k, l, o, p, ch, t, g, y, mn, mx, mx2, q,
    q1, q2;
vector<long long> v;
vector<long long> v2;
long long A[100001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    c = 0;
    f = 0;
    g = 0;
    for (i = 0; i < n; i++) {
      cin >> a;
      if (a > 0) {
        f += a;
        v.push_back(a);
      } else {
        a = abs(a);
        j = c;
        if (c != v.size())
          for (j = c; j < v.size(); j++) {
            if (v[j] > a) {
              g += a;
              v[j] -= a;
              break;
            } else {
              a -= v[j];
              g += v[j];
            }
          }
        c = j;
      }
    }
    if (v.size() > 0) v.clear();
    cout << f - g << "\n";
  }
}
