#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, a, b, c, d, i, j, k, l, n, m, x, y;
  cin >> t;
  while (t--) {
    cin >> n;
    long long int s[n + 5];
    for (i = 0; i < n; i++) cin >> s[i];
    l = 0;
    k = 0;
    a = 0;
    x = 0;
    b = 0;
    long long int h[n + 5];
    j = 0;
    k = 0;
    for (i = 0; i < n; i++) {
      k += s[i];
      if (k < 0) {
        j += (abs(k));
        k = 0;
      }
    }
    cout << (k + j) / 2 << endl;
  }
}
