#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e5 + 10;
long long a[MAX];
void solve() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long shu = 0;
  long long jian = 0;
  long long res = 0;
  for (long long i = 0; i < n; i++) {
    res += abs(a[i]);
    if (a[i] < 0) {
      jian += min(abs(a[i]), shu);
      shu -= min(abs(a[i]), shu);
    }
    if (a[i] > 0) {
      shu += a[i];
    }
  }
  cout << (res - jian * 2) / 2 << '\n';
}
signed main() {
  long long _ = 1;
  cin >> _;
  while (_--) {
    solve();
  }
  return 0;
}
