#include <bits/stdc++.h>
using namespace std;
long long int n, m, k, g, mx, mn, res, c, x, y, z, w, p, q, r, l, s, t;
int main() {
  ios::sync_with_stdio(0);
  cin >> t;
  for (long long int ca = 0; ca < t; ca++) {
    cin >> n;
    vector<long long int> a(n), b;
    for (auto &x : a) cin >> x;
    res = 0;
    for (long long int i = n - 1; i >= 0; i--) {
      if (a[i] < 0)
        res += (-a[i]);
      else {
        mn = min(a[i], res);
        a[i] -= mn;
        res -= mn;
      }
    }
    res = 0;
    for (long long int i = 0; i < n; i++)
      if (a[i] > 0) res += a[i];
    cout << res << endl;
  }
  return 0;
}
