#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long arr[n];
    vector<long long> vpos;
    vector<long long> vneg;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] < 0) vneg.push_back(i);
      if (arr[i] > 0) vpos.push_back(i);
    }
    long long res = 0;
    auto jj = vneg.begin();
    for (auto i = vpos.begin(); i != vpos.end(); i++) {
      if (*i > *(vneg.end() - 1)) break;
      for (auto j = jj; j != vneg.end(); j++) {
        if (*j < *i) continue;
        if (arr[*i] <= abs(arr[*j])) {
          arr[*j] += arr[*i];
          arr[*i] = 0;
          jj = j;
          break;
        }
        if (arr[*i] > abs(arr[*j])) {
          arr[*i] += arr[*j];
          arr[*j] = 0;
        }
      }
    }
    for (auto i = vneg.begin(); i != vneg.end(); i++) {
      res += abs(arr[*i]);
    }
    cout << res << endl;
  }
  return 0;
}
