#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mx = 1e5 + 10;
long long int binpow(long long int base, long long int exp) {
  long long int res = 1;
  while (1) {
    if (exp & 1) res *= base;
    exp >>= 1;
    if (!exp) break;
    base *= base;
  }
  return res;
}
void solve() {
  int n;
  cin >> n;
  long long int arr[n + 10];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  long long int pos = 0;
  for (int i = 0; i < n; ++i) {
    if (arr[i] < 0) {
      if (pos >= abs(arr[i])) {
        pos += arr[i];
        arr[i] = 0;
      } else {
        arr[i] += pos;
        pos = 0;
      }
    } else if (arr[i] > 0) {
      pos += arr[i];
    }
  }
  long long int val = 0;
  for (int i = 0; i < n; ++i) {
    if (arr[i] < 0) val += arr[i];
  }
  cout << abs(val) << "\n";
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t, cs = 0;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
