#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (auto& ai : a) {
      cin >> ai;
    }
    long long ans = 0;
    int i = 0;
    while (a[i] >= 0 && i < n) {
      i++;
    }
    if (i == n) {
      cout << 0 << endl;
      continue;
    }
    long long pos = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] >= 0) {
        pos += a[j];
      } else if (a[j] < 0) {
        if (-a[j] <= pos) {
          pos += a[j];
          a[j] = 0;
        } else {
          a[j] += pos;
          pos = 0;
          a[n - 1] += -a[j];
          ans += (-a[j]);
          a[j] = 0;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
