#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v;
    long long pos = 0, sum = 0;
    for (long long i = 0; i < n; ++i) {
      long long elem;
      cin >> elem;
      if (elem > 0) sum += elem;
      if (v.empty() && elem != 0) {
        v.push_back(elem);
      } else if (elem == 0)
        continue;
      else if (v[pos] < 0 && elem < 0 || v[pos] > 0 && elem > 0) {
        v[pos] += elem;
      } else {
        v.push_back(elem);
        pos++;
      }
    }
    if (v.size() == 0)
      cout << 0 << '\n';
    else {
      for (long long i = v.size() - 1; i >= 0; --i) {
        if (v[i] < 0) {
          continue;
        }
        if (i == v.size() - 1) continue;
        if (v[i] > -v[i + 1]) {
          sum += v[i + 1];
        } else if (v[i] < -v[i + 1]) {
          sum -= v[i];
          v[i + 1] += v[i];
          if (i >= 1) v[i - 1] += v[i + 1];
        } else {
          sum += v[i + 1];
        }
      }
      cout << sum << '\n';
    }
  }
  return 0;
}
