#include <bits/stdc++.h>
using namespace std;
bool compare(const pair<int, int>& i, const pair<int, int>& j) {
  return i.first < j.first;
}
int ncr(int n, int k) {
  if (n < k) return 0;
  int C[n + 1][k + 1];
  int i, j;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= min(i, k); j++) {
      if (j == 0 || j == i)
        C[i][j] = 1;
      else
        C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 1000000007;
    }
  }
  return C[n][k];
}
long long modpowIter(long long a, long long b, long long c) {
  long long ans = 1;
  while (b != 0) {
    if (b % 2 == 1) ans = (ans * a) % LLONG_MAX;
    a = (a * a) % LLONG_MAX;
    b /= 2;
  }
  return ans;
}
string intobin(int n) {
  string s = "";
  if (n == 0) s = "0";
  while (n) {
    if (n % 2)
      s = "1" + s;
    else
      s = "0" + s;
    n /= 2;
  }
  return s;
}
int bintoin(string s) {
  long long n = 0;
  vector<long long> v;
  v.push_back(1);
  for (int i = 0; i < 400; i++) {
    v.push_back((v[v.size() - 1] * 2) % 1000003);
  }
  for (int i = s.length() - 1; i > -1; i--) {
    n = (n + (s[i] - '0') * v[s.length() - i - 1]) % 1000003;
  }
  return n;
}
long long nc2(long long n, long long k) {
  if (n < k) return 0;
  return (n * (n - 1)) / 2;
}
bool prime[1000001];
void SieveOfEratosthenes(int n) {
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
int parent[6];
void make_set(int v) { parent[v] = v; }
int find_set(int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) parent[b] = a;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long summ = 0;
    long long result = 0;
    for (long long i = 0; i <= n - 1; i++) {
      if (a[i] > 0)
        summ += a[i];
      else {
        if (abs(a[i]) <= summ)
          summ += a[i];
        else {
          result += abs(a[i]) - summ;
          summ = 0;
        }
      }
    }
    cout << result << "\n";
  }
  return 0;
}
