#include <bits/stdc++.h>
using namespace std;
const bool debug = 0;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int _;
  cin >> _;
  while (_--) {
    int n;
    cin >> n;
    vector<long long int> a(n);
    for (long long int& x : a) cin >> x;
    vector<int> pos;
    for (int i = 0; i < n; ++i) {
      if (a[i] > 0) pos.push_back(i);
    }
    int r = n - 1;
    long long int ans = 0;
    while (!pos.empty()) {
      while (r > pos.back() && a[r] >= 0) r--;
      if (a[r] >= 0) {
        ans += a[pos.back()];
        a[pos.back()] = 0;
        pos.pop_back();
        continue;
      }
      int mn = min(-a[r], a[pos.back()]);
      a[pos.back()] -= mn;
      a[r] += mn;
      if (!a[pos.back()]) pos.pop_back();
    }
    for (int i = 0; i < n; ++i) {
      if (a[i] > 0) ans += a[i];
    }
    cout << ans << '\n';
  }
  return 0;
}
