#include <bits/stdc++.h>
using namespace std;
const int64_t mod = 1000000007;
int main() {
  int64_t t;
  cin >> t;
  while (t--) {
    int64_t n;
    cin >> n;
    int64_t a[n];
    int64_t sum = 0, res = 0;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      if (a[i] < 0) {
        if (sum >= abs(a[i])) {
          sum -= abs(a[i]);
        } else {
          res += abs(a[i]) - sum;
          sum = 0;
        }
      } else
        sum += a[i];
    }
    cout << res << "\n";
  }
}
