#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  long long coins = 0;
  vector<long long> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  int i = 0, j = 0;
  while (i < n && j < n) {
    while (i < n && arr[i] <= 0) i++;
    while (j < n && (arr[j] >= 0 || j < i)) j++;
    if (i >= n || j >= n) break;
    long long x = min(abs(arr[i]), abs(arr[j]));
    arr[i] -= x;
    arr[j] += x;
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] > 0) coins += arr[i];
  }
  cout << coins << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
