#include <bits/stdc++.h>
using namespace std;
long long T, n, s, sum;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  cin >> T;
  while (T--) {
    cin >> n;
    sum = 0;
    long long a[100010] = {0};
    for (int i = 1; i <= n; i++) {
      cin >> s;
      a[i] += s;
      if (a[i] > 0) a[i + 1] += a[i];
      if (a[i] < 0) sum -= a[i];
    }
    cout << sum << endl;
  }
}
