#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long a[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    long long ans = 0, tmp = 0;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      if (a[i] >= 0)
        tmp += a[i];
      else {
        long long x = a[i];
        a[i] += min(tmp, abs(x));
        tmp -= min(tmp, abs(x));
      }
    }
    cout << tmp << '\n';
  }
  return 0;
}
