#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 2e5 + 1;
long long add(long long a, long long b) {
  return ((a % mod) + (b % mod)) % mod;
}
long long mul(long long a, long long b) {
  return ((a % mod) * (b % mod)) % mod;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    long long sum = 0;
    for (long long i = 0; i < n; i++) cin >> a[i];
    vector<long long> ans;
    for (long long i = 0; i < n; i++) {
      if (sum + a[i] >= 0) {
        sum += a[i];
      } else {
        ans.push_back(sum + a[i]);
        sum = 0;
      }
    }
    long long res = 0;
    for (auto &x : ans) {
      res += x;
    }
    res = abs(res);
    cout << res << "\n";
  }
}
