#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
class node {
 public:
  int f1;
  node *left;
  node *right;
  node(int f1) {
    this->f1 = f1;
    this->left = nullptr;
    this->right = nullptr;
  }
};
long long gcd(long long a, long long b) {
  if (b > a) {
    return gcd(b, a);
  }
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
void swap(int &a, int &b) {
  int t = a;
  a = b;
  b = t;
}
struct compare {
  bool operator()(node const &i1, node const &i2) { return (i1.f1 > i2.f1); }
};
bool IsApproximatelyEqual(double x, double y, double epsilon) {
  if ((-epsilon <= (x - y)) && ((x - y) <= epsilon)) return true;
  if (((-epsilon <= x) && (x <= epsilon)) ||
      ((-epsilon <= y) && (y <= epsilon)))
    return false;
  return ((-epsilon <= ((x - y) / x)) && (((x - y) / x) <= epsilon)) ||
         ((-epsilon <= ((x - y) / y)) && (((x - y) / y) <= epsilon));
}
bool compareInterval(node i1, node i2) { return (i1.f1 < i2.f1); }
long long getlen(char *s) {
  long long k = 0;
  while (*s != '\0') {
    s += 1;
    k += 1;
  }
  return k;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, t, ar[100005], r1;
  long long co;
  stack<int> s;
  cin >> t;
  while (t-- > 0) {
    co = 0;
    cin >> n;
    for (int(i) = 0; (i) < (int)(n); (i)++) {
      cin >> ar[i];
    }
    for (int(i) = 0; (i) < (int)(n); (i)++) {
      if (ar[i] == 0) continue;
      if (s.empty()) {
        s.push(ar[i]);
        continue;
      }
      if (ar[i] < 0) {
        while (!s.empty() && s.top() > 0) {
          r1 = min(abs(ar[i]), s.top());
          s.top() -= r1;
          ar[i] += r1;
          if (s.top() == 0) s.pop();
          if (ar[i] == 0) break;
        }
        if (ar[i] < 0) s.push(ar[i]);
      } else {
        s.push(ar[i]);
      }
    }
    while (!s.empty()) {
      if (s.top() > 0) {
        co += s.top();
      }
      s.pop();
    }
    cout << co << endl;
  }
}
