#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
struct node {
  int cnt, p;
};
vector<node> key1, key2;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] > 0) key1.push_back(node{a[i], i});
      if (a[i] < 0) key2.push_back(node{-a[i], i});
    }
    int nowp = 0;
    bool flag = 1;
    long long ans = 0;
    while (!key1.empty()) {
      node &now = key1[0];
      while (flag && nowp < key2.size() && key2[nowp].p < now.p) nowp++;
      if (nowp == key2.size()) flag = 0;
      if (!flag) nowp = 0;
      node &nxt = key2[nowp];
      if (now.p > nxt.p) {
        int key = min(now.cnt, nxt.cnt);
        now.cnt -= key;
        nxt.cnt -= key;
        ans += key;
        if (now.cnt == 0)
          key1.erase(key1.begin());
        else
          key2.erase(key2.begin() + nowp);
      } else {
        int key = min(now.cnt, nxt.cnt);
        now.cnt -= key;
        nxt.cnt -= key;
        if (now.cnt == 0)
          key1.erase(key1.begin());
        else
          key2.erase(key2.begin() + nowp);
      }
    }
    cout << ans << endl;
  }
}
