#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10, MOD = 1e9 + 7;
const int maxn = 2e5;
const long double eps = 1e-5;
const int EPS = 500 * 500;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long first = 1;
  while (!isdigit(ch)) {
    if (ch == '-') first *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= first;
}
template <typename T, typename... Args>
void read(T &first, Args &...args) {
  read(first);
  read(args...);
}
int n, m, d;
pair<long long, long long> pos[maxn], neg[maxn];
int pos1, neg1;
int main() {
  int T;
  cin >> T;
  while (T--) {
    cin >> n;
    pos1 = neg1 = 0;
    for (int i = 0; i < n; ++i) {
      cin >> m;
      if (m > 0)
        pos[pos1++] = {m, i};
      else if (m < 0)
        neg[neg1++] = {m, i};
    }
    int i = 0, j = 0;
    while (i < pos1 && j < neg1) {
      if (pos[i].second > neg[j].second)
        j++;
      else {
        long long minv = min(pos[i].first, -neg[j].first);
        pos[i].first -= minv;
        neg[j].first += minv;
        if (!pos[i].first) i++;
        if (!neg[j].first) j++;
      }
    }
    long long ans = 0;
    for (int i = 0; i < pos1; ++i) ans += pos[i].first;
    cout << ans << endl;
  }
  return 0;
}
