#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y % 2 == 1) res *= x;
    y /= 2;
    x *= x;
  }
  return res;
}
long long solve() {
  long long n;
  cin >> n;
  vector<long long> v(n, 0);
  for (long long i = 0; i < n; i++) cin >> v[i];
  ;
  long long count = 0, num = 0, sum = 0;
  for (long long i = 0; i < n; i++) {
    sum += abs(v[i]);
    if (v[i] < 0 && num <= 0) {
      num = 0;
    } else if (v[i] < 0 && num > 0) {
      long long temp = 0;
      temp = min(num, abs(v[i]));
      count += temp;
      num -= temp;
    } else if (v[i] > 0)
      num += v[i];
  }
  cout << (sum - (2 * count)) / 2 << endl;
  return 0;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  long long test;
  cin >> test;
  while (test--) {
    solve();
  }
}
