#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = 0x3f3f3f3f3f3f3f3f;
double pi = acos(-1.0);
const long long maxn = 1e5 + 10;
long long T, N, arr[maxn];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> T;
  while (T--) {
    cin >> N;
    for (register long long i = 1; i <= N; ++i) {
      cin >> arr[i];
    }
    long long sum = 0, ans = 0;
    for (long long i = 1; i <= N; ++i) {
      if (arr[i] < 0) {
        long long tmp = min(-arr[i], sum);
        arr[i] += tmp;
        ans += abs(arr[i]);
        sum -= tmp;
      } else {
        sum += arr[i];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
