#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    set<int, greater<int>> pos;
    for (int i = 0; i < n; ++i) {
      cin >> arr[i];
      if (arr[i] > 0) pos.insert(i);
    }
    long long ans = 0;
    for (int i = n - 1; i >= 0; --i) {
      if (arr[i] >= 0) continue;
      auto it = pos.lower_bound(i - 1);
      if (it == pos.end())
        ans -= arr[i];
      else {
        int y = *it;
        int z = min(-arr[i], arr[y]);
        arr[i] += z;
        arr[y] -= z;
        if (arr[y] == 0) pos.erase(it);
        if (arr[i] != 0) ++i;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
