#include <bits/stdc++.h>
using namespace std;
long long powe(long long a, long long b) {
  long long n = 1;
  while (b) {
    if (b & 1) {
      n *= a;
      n %= 1000000007;
    }
    a *= a;
    a %= 1000000007;
    b /= 2;
  }
  return n;
}
void solve() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long total{0};
  long long temp{0};
  for (int i = 0; i < n; i++) {
    if (a[i] > 0) {
      total += a[i];
    } else {
      temp = min(abs(a[i]), total);
      a[i] += temp;
      total -= temp;
    }
  }
  total = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < 0) total += abs(a[i]);
  }
  cout << total << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc{1};
  cin >> tc;
  while (tc--) {
    solve();
  }
  return 0;
}
