#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
int main() {
  fast();
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    long long int ans = 0;
    long long int i = 0;
    if (a[i] < 0) {
      while (a[i] < 0) {
        ans = ans + (-1 * a[i]);
        i++;
      }
    }
    long long int sum_pos = 0;
    for (long long int j = i; j < n; j++) {
      if (a[j] >= 0)
        sum_pos = sum_pos + a[j];
      else {
        long long int sum_neg = 0;
        while (a[j] < 0 && j < n) {
          sum_neg = sum_neg + (-1 * a[j]);
          j++;
        }
        j--;
        if (sum_neg > sum_pos) {
          ans = ans + (sum_neg - sum_pos);
          sum_pos = 0;
        } else {
          sum_pos = sum_pos - sum_neg;
        }
      }
    }
    cout << ans << "\n";
  }
}
