#include <bits/stdc++.h>
using namespace std;
using INT = long long;
using pii = pair<int, int>;
INT a[100010];
int main() {
  int t;
  for (cin >> t; t--;) {
    int n;
    INT sum = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], sum += abs(a[i]);
    sum >>= 1ll;
    INT inc = 0, dec = 0;
    INT ans = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == 0) continue;
      if (inc + dec >= sum) break;
      if (a[i] > 0) {
        INT val = sum - (inc + dec);
        dec += min(val, a[i]);
        a[i] -= min(val, a[i]);
      } else {
        INT val = min(dec, abs(a[i]));
        inc += val, dec -= val;
        a[i] += val;
        if (a[i]) inc += abs(a[i]), ans += abs(a[i]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
