#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> arr(n);
    for (long long i = 0; i < n; i++) {
      cin >> arr[i];
    }
    long long psum = 0;
    for (long long i = 0; i < n; i++) {
      if (arr[i] < 0) {
        arr[i] = arr[i] + psum;
        if (arr[i] > 0) {
          psum = arr[i];
          arr[i] = 0;
        } else {
          psum = 0;
        }
      } else {
        psum += arr[i];
      }
    }
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      if (arr[i] < 0) {
        ans += abs(arr[i]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
