#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000007LL;
const long long MAXN = 150000LL;
const double EPS = 1e-10;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> arr(n);
    for (long long& x : arr) {
      cin >> x;
    }
    long long sum = 0LL;
    long long ans = 0LL;
    for (long long i = 0LL; i < n; i++) {
      if (arr[i] >= 0LL) {
        sum += arr[i];
        arr[i] = 0LL;
      } else {
        if (sum >= abs(arr[i])) {
          sum -= abs(arr[i]);
          arr[i] = 0LL;
        } else {
          arr[i] += sum;
          sum = 0LL;
        }
      }
    }
    for (long long i = 0LL; i < n; i++) {
      if (arr[i] < 0LL) {
        ans += abs(arr[i]);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
