#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define ll long long

using namespace std;

vector < int > d1, d2;
vector < int > mem;
int st = 0;

int find_max(int v, int l, int r, int cl, int cr) {
    if (cl >= r || cr <= l) return -1e9;
    if (cl >= l && cr <= r) return d1[v];
    int mid = (cl + cr) / 2;
    return max(find_max(v * 2, l, r, cl, mid), find_max(v * 2 + 1, l, r, mid, cr));
}

int find_min(int v, int l, int r, int cl, int cr) {
    if (cl >= r || cr <= l) return 1e9;
    if (cl >= l && cr <= r) return d2[v];
    int mid = (cl + cr) / 2;
    return min(find_min(v * 2, l, r, cl, mid), find_min(v * 2 + 1, l, r, mid, cr));
}

int kek(int v, int l, int r, int cl, int cr) {
    if (cl >= r || cr <= l) return 1e9;
    if (cl >= l && cr <= r) return mem[v];
    int mid = (cl + cr) / 2;
    return min(kek(v * 2, l, r, cl, mid), kek(v * 2 + 1, l , r, mid, cr));
}

void upd(int v) {
    v += (1 << st);
    v /= 2;
    while (v > 0) {
        mem[v] = min(mem[v * 2], mem[v * 2 + 1]);
        v /= 2;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#else
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif
    //YA IZVINYAUS
    int n, s, l;
    cin >> n >> s >> l;
    while (1 << st < n)
        ++st;
    d1.resize(1 << (st + 1), -1e9);
    d2.resize(1 << (st + 1), 1e9);
    mem.resize(1 << (st + 1), 1e9);
    vector < int > f(n, 0);
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        d1[(1 << st) + i] = a[i];
        d2[(1 << st) + i] = a[i];
    }
    for (int i = (1 << st) - 1; i > 0; --i) {
        d1[i] = max(d1[i * 2], d1[i * 2 + 1]);
        d2[i] = min(d2[i * 2], d2[i * 2 + 1]);
    }
    for (int i = 0; i < n; ++i) {
        if (i > 0) f[i] = f[i - 1];
        while (find_max(1, f[i], i + 1, 0, 1 << st) - find_min(1, f[i], i + 1, 0, 1 << st) > s)
            ++f[i];
    }
    vector < int > dp(n, 1e9);
    for (int i = 0; i < n; ++i) {
        if (!i && l == 1) dp[i] = 1;
        else if (f[i] == 0 && i + 1 >= l) dp[i] = 1;
        else if (i + 1 - f[i] >= l) {
            int z7z8 = max(i - l, 0), z38 = max(f[i] - 1, 0);
            if (z7z8 > z38) swap(z7z8, z38);
            int j = kek(1, z7z8, z38 + 1, 0, 1 << st);
            dp[i] = j + 1;
        }
        mem[(1 << st) + i] = dp[i];
        upd(i);
    }
//    for (int i = 0; i < n; ++i)
//        cout << dp[i] << ' ';
    if (dp[n - 1] >= 1e9) dp[n - 1] = -1;
    cout << dp[n - 1];
    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

int ar[100100],treeMax[400100],treeMin[400100],inf=1e9;
int n,m,o,last=-1,cnt,mx,mn,ans;

void build_max(int node, int a, int b) {
    if(a > b) return; // Out of range

  	if(a == b) { // Leaf node
    		treeMax[node] = ar[a]; // Init value
		return;
	}

	build_max(node*2, a, (a+b)/2); // Init left child
	build_max(node*2+1, 1+(a+b)/2, b); // Init right child

	treeMax[node] = max(treeMax[node*2], treeMax[node*2+1]); // Init root value
}

void build_min(int node, int a, int b) {
    if(a > b) return; // Out of range

  	if(a == b) { // Leaf node
    	treeMin[node] = ar[a]; // Init value
		return;
	}

	build_min(node*2, a, (a+b)/2); // Init left child
	build_min(node*2+1, 1+(a+b)/2, b); // Init right child

	treeMin[node] = min(treeMin[node*2], treeMin[node*2+1]); // Init root value
}

int query_max(int node, int a, int b, int i, int j) {

	if(a > b || a > j || b < i) return -inf; // Out of range

	if(a >= i && b <= j) // Current segment is totally within range [i, j]
		return treeMax[node];

	int q1 = query_max(node*2, a, (a+b)/2, i, j); // Query left child
	int q2 = query_max(1+node*2, 1+(a+b)/2, b, i, j); // Query right child

	int res = max(q1, q2); // Return final result

	return res;
}

int query_min(int node, int a, int b, int i, int j) {

	if(a > b || a > j || b < i) return inf; // Out of range

	if(a >= i && b <= j) // Current segment is totally within range [i, j]
		return treeMin[node];

	int q1 = query_min(node*2, a, (a+b)/2, i, j); // Query left child
	int q2 = query_min(1+node*2, 1+(a+b)/2, b, i, j); // Query right child

	int res = min(q1, q2); // Return final result

	return res;
}

int main() {
	scanf("%d %d %d",&n,&m,&o);
	for(int i=0;i<n;i++) scanf("%d",&ar[i]);
	build_max(1,0,n-1);
	build_min(1,0,n-1);
	bool check = true;
	for(int i=0;i<n;i++){
		cnt=0;
		mx=-1e9;
		mn=1e9;
		for(int j=i;j<n;j++){
			mx=max(mx,ar[j]);
			mn=min(mn,ar[j]);
			if(mx-mn>m) break;
			cnt++;
		}
		if(cnt>=o){
			ans++;
			last = i+o-1;
			i += cnt-1;
		}
		else{
			int left = o-cnt;
			if(i-left<=last){
				check=false;
				break;
			}
			mx = query_max(1,0,n-1,i-left,i+cnt-1);
			mn = query_min(1,0,n-1,i-left,i+cnt-1);
			if(mx-mn>m){
				check=false;
				break;
			}
			ans++;
			i += cnt-1;
			last = i;
		}
		//cout<<ans<<" "<<i<<" "<<last<<" "<<cnt<<endl;
	}
	if(check){
		printf("%d\n",ans);
		return 0;
	}
	check = true;
	reverse(ar,ar+n);
	build_max(1,0,n-1);
	build_min(1,0,n-1);
	ans=0,last=-1;
	for(int i=0;i<n;i++){
		cnt=0;
		mx=-1e9;
		mn=1e9;
		for(int j=i;j<n;j++){
			mx=max(mx,ar[j]);
			mn=min(mn,ar[j]);
			if(mx-mn>m) break;
			cnt++;
		}
		if(cnt>=o){
			ans++;
			last = i+o-1;
			i += cnt-1;
		}
		else{
			int left = o-cnt;
			if(i-left<=last){
				check=false;
				break;
			}
			mx = query_max(1,0,n-1,i-left,i+cnt-1);
			mn = query_min(1,0,n-1,i-left,i+cnt-1);
			if(mx-mn>m){
				check=false;
				break;
			}
			ans++;
			i += cnt-1;
			last = i;
		}
		//cout<<ans<<" "<<i<<" "<<last<<" "<<cnt<<endl;
	}
	if(check) printf("%d\n",ans);
	else printf("-1\n");
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
ll mpow(ll a, ll n,ll mod)
{ll ret=1;ll b=a;while(n) {if(n&1)
    ret=(ret*b)%mod;b=(b*b)%mod;n>>=1;}
return (ll)ret;
}
using namespace std;
#define sd(x) scanf("%d",&x)
#define pd(x) printf("%d",x)
#define sl(x) scanf("%lld",&x)
#define pl(x) printf("%lld",x)
#define mem(x,a) memset(x,a,sizeof(x))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define N (int)(1e5+205)
int dp1[N][22],dp2[N][22],a[N],n,s,l;
int DP[N];
void pre(){
    for(int i=1;i<=n;i++){
        dp1[i][0]=a[i];
        dp2[i][0]=a[i];
    }
    for(int i=1;(1<<i)<=n;i++){
        for(int j=1;j+(1<<i)-1<=n;j++){
            dp1[j][i]=max(dp1[j][i-1],dp1[j+(1<<(i-1))][i-1]);
            dp2[j][i]=min(dp2[j][i-1],dp2[j+(1<<(i-1))][i-1]);
        }
    }
}
int rmq(int i,int j){
    int len=j-i+1;
    int p=0;
    while((1<<p)<=len)p++;
    p--;
    int x=max(dp1[i][p],dp1[j-(1<<p)+1][p]);
    int y=min(dp2[i][p],dp2[j-(1<<p)+1][p]);
    return abs(x-y)<=s;
}
int seg[4*N];
int merg(int x1,int x2){
    if(!x1&&!x2){
        return 0;
    }
    if(x1==0){
        return x2;
    }
    if(x2==0){
        return x1;
    }
    if(DP[x1]>DP[x2]){
        return x2;
    }
    return x1;
}
void update(int i,int l,int r,int x){
    if(x<l||x>r){
        return;
    }
    if(l==r&&l==x){
        seg[i]=x;
        return;
    }
    int mid=(l+r)>>1;
    update(2*i,l,mid,x);
    update(2*i+1,mid+1,r,x);
    seg[i]=merg(seg[2*i],seg[2*i+1]);
}
int query(int i,int l,int r,int ql,int qr){
    if(qr<l||ql>r){
        return 0;
    }
    if(ql<=l&&r<=qr){
        return seg[i];
    }
    int mid=(l+r)>>1;
    int q1=query(2*i,l,mid,ql,qr);
    int q2=query(2*i+1,mid+1,r,ql,qr);
    return merg(q1,q2);
}
void solve(){
    sd(n);sd(s);sd(l);
    for(int i=1;i<=n;i++){
        sd(a[i]);
    }
    pre();
    for(int i=1;i<=l-1;i++){
        DP[i]=0;
        update(1,1,n,i);
    }
    for(int i=l;i<=n;i++){
        DP[i]=1e9;
        update(1,1,n,i);
    }
    DP[0]=0;
    for(int i=l;i<=n;i++){
        int lo=1,hi=i-l+2;
        while(lo<hi){
            int mid=(lo+hi)>>1;
            if(rmq(mid,i)){
                hi=mid;
            }
            else{
                lo=mid+1;
            }
        }
        if(lo>i-l+1){
            continue;
        }
        else{
            int q=query(1,1,n,lo,i-l+1);
            DP[i]=min(DP[i],DP[max(q-1,0)]+1);
            update(1,1,n,i);
        }
    }
    if(DP[n]==1e9)
        printf("-1");
    else
        pd(DP[n]);
}
int main(){
   //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   int t=1;
   //sd(t);
   for(int i=1;i<=t;i++){
       //printf("Case #%d:\n",i);
       solve();
   }
   return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
ll mpow(ll a, ll n,ll mod)
{ll ret=1;ll b=a;while(n) {if(n&1)
    ret=(ret*b)%mod;b=(b*b)%mod;n>>=1;}
return (ll)ret;
}
using namespace std;
#define sd(x) scanf("%d",&x)
#define pd(x) printf("%d",x)
#define sl(x) scanf("%lld",&x)
#define pl(x) printf("%lld",x)
#define mem(x,a) memset(x,a,sizeof(x))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define N (int)(1e5+205)
int dp1[N][22],dp2[N][22],a[N],n,s,l;
int DP[N];
void pre(){
    for(int i=1;i<=n;i++){
        dp1[i][0]=a[i];
        dp2[i][0]=a[i];
    }
    for(int i=1;(1<<i)<=n;i++){
        for(int j=1;j+(1<<i)-1<=n;j++){
            dp1[j][i]=max(dp1[j][i-1],dp1[j+(1<<(i-1))][i-1]);
            dp2[j][i]=min(dp2[j][i-1],dp2[j+(1<<(i-1))][i-1]);
        }
    }
}
int rmq(int i,int j){
    int len=j-i+1;
    int p=0;
    while((1<<p)<=len)p++;
    p--;
    int x=max(dp1[i][p],dp1[j-(1<<p)+1][p]);
    int y=min(dp2[i][p],dp2[j-(1<<p)+1][p]);
    return abs(x-y)<=s;
}
int seg[4*N];
int merg(int x1,int x2){
    if(DP[x1]>DP[x2]){
        return x2;
    }
    return x1;
}
void build(int i,int l,int r){
    if(l==r){
        seg[i]=n+1;
        return;
    }
    int mid=(l+r)>>1;
    build(2*i,l,mid);
    build(2*i+1,mid+1,r);
    seg[i]=n+1;
    seg[2*i]=n+1;
    seg[2*i+1]=n+1;
}
void update(int i,int l,int r,int x){
    if(x<l||x>r){
        return;
    }
    if(l==r&&l==x){
        seg[i]=x;
        return;
    }
    int mid=(l+r)>>1;
    update(2*i,l,mid,x);
    update(2*i+1,mid+1,r,x);
    seg[i]=merg(seg[2*i],seg[2*i+1]);
}
int query(int i,int l,int r,int ql,int qr){
    if(qr<l||ql>r){
        return n+1;
    }
    if(ql<=l&&r<=qr){
        return seg[i];
    }
    int mid=(l+r)>>1;
    int q1=query(2*i,l,mid,ql,qr);
    int q2=query(2*i+1,mid+1,r,ql,qr);
    return merg(q1,q2);
}
void solve(){
    sd(n);sd(s);sd(l);
    for(int i=1;i<=n;i++){
        sd(a[i]);
    }
    pre();
    build(1,0,n);
    DP[n+1]=1e9;
    for(int i=0;i<=l-1;i++){
        DP[i]=0;
        update(1,0,n,i);
    }
    for(int i=l;i<=n;i++){
        DP[i]=1e9;
        update(1,0,n,i);
    }
    for(int i=l;i<=n;i++){
        int lo=1,hi=i-l+2;
        while(lo<hi){
            int mid=(lo+hi)>>1;
            if(rmq(mid,i)){
                hi=mid;
            }
            else{
                lo=mid+1;
            }
        }
        if(lo>i-l+1){
            continue;
        }
        else{
            int q=query(1,0,n,lo-1,i-l);
            DP[i]=min(DP[i],DP[q]+1);
            update(1,0,n,i);
        }
    }
    if(DP[n]>=1e9)
        printf("-1");
    else
        pd(DP[n]);
}
int main(){
   //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   int t=1;
   //sd(t);
   for(int i=1;i<=t;i++){
       //printf("Case #%d:\n",i);
       solve();
   }
   return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
ll mpow(ll a, ll n,ll mod)
{ll ret=1;ll b=a;while(n) {if(n&1)
    ret=(ret*b)%mod;b=(b*b)%mod;n>>=1;}
return (ll)ret;
}
using namespace std;
#define sd(x) scanf("%d",&x)
#define pd(x) printf("%d",x)
#define sl(x) scanf("%lld",&x)
#define pl(x) printf("%lld",x)
#define mem(x,a) memset(x,a,sizeof(x))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define N (int)(1e5+205)
int dp1[N][22],dp2[N][22],a[N],n,s,l;
int DP[N];
void pre(){
    for(int i=1;i<=n;i++){
        dp1[i][0]=a[i];
        dp2[i][0]=a[i];
    }
    for(int i=1;(1<<i)<=n;i++){
        for(int j=1;j+(1<<i)-1<=n;j++){
            dp1[j][i]=max(dp1[j][i-1],dp1[j+(1<<(i-1))][i-1]);
            dp2[j][i]=min(dp2[j][i-1],dp2[j+(1<<(i-1))][i-1]);
        }
    }
}
int rmq(int i,int j){
    int len=j-i+1;
    int p=0;
    while((1<<p)<=len)p++;
    p--;
    int x=max(dp1[i][p],dp1[j-(1<<p)+1][p]);
    int y=min(dp2[i][p],dp2[j-(1<<p)+1][p]);
    return abs(x-y)<=s;
}
int seg[4*N];
int merg(int x1,int x2){
    if(!x1&&!x2){
        return 0;
    }
    if(x1==0){
        return x2;
    }
    if(x2==0){
        return x1;
    }
    if(DP[x1]>DP[x2]){
        return x2;
    }
    return x1;
}
void update(int i,int l,int r,int x){
    if(x<l||x>r){
        return;
    }
    if(l==r&&l==x){
        seg[i]=x;
        return;
    }
    int mid=(l+r)>>1;
    update(2*i,l,mid,x);
    update(2*i+1,mid+1,r,x);
    seg[i]=merg(seg[2*i],seg[2*i+1]);
}
int query(int i,int l,int r,int ql,int qr){
    if(qr<l||ql>r){
        return 0;
    }
    if(ql<=l&&r<=qr){
        return seg[i];
    }
    int mid=(l+r)>>1;
    int q1=query(2*i,l,mid,ql,qr);
    int q2=query(2*i+1,mid+1,r,ql,qr);
    return merg(q1,q2);
}
void solve(){
    sd(n);sd(s);sd(l);
    for(int i=1;i<=n;i++){
        sd(a[i]);
    }
    pre();
    for(int i=1;i<=l-1;i++){
        DP[i]=0;
        update(1,1,n,i);
    }
    for(int i=l;i<=n;i++){
        DP[i]=1e9;
        update(1,1,n,i);
    }
    DP[0]=0;
    for(int i=l;i<=n;i++){
        int lo=1,hi=i-l+2;
        while(lo<hi){
            int mid=(lo+hi)>>1;
            if(rmq(mid,i)){
                hi=mid;
            }
            else{
                lo=mid+1;
            }
        }
        if(lo>i-l+1){
            continue;
        }
        else{
            int q=query(1,1,n,lo,i-l+1);
            if(q==0)
                continue;
            DP[i]=min(DP[i],DP[max(q-1,0)]+1);
            update(1,1,n,i);
        }
    }
    if(DP[n]>=1e9)
        printf("-1");
    else
        pd(DP[n]);
}
int main(){
   //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   int t=1;
   //sd(t);
   for(int i=1;i<=t;i++){
       //printf("Case #%d:\n",i);
       solve();
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main(){
	fast();
	int t;
	cin>>t;

    while(t--){
        int n;
        cin>>n;
        lli sum=0;
        for(int i=0;i<n;i++){
            lli x;
            cin>>x;
            sum=max(0ll,sum+x);
        }

        cout<<sum<<"\n";
    }

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main(){
	fast();
	int t;
	cin>>t;

    while(t--){
        int n;
        cin>>n;
        int a[n];
        lli sum=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum=max(0ll,sum+a[i]);
        }

        cout<<sum<<"\n";
    }

	return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#define  PB push_back
#define  pB pop_back
#define  MP make_pair
#define  endl "\n"
#define  pi 3.14159265358979323846
using ll = long long;
using namespace std;
const int INF = 1e9;
const int N = 2e5+5;
const ll MOD = 1e9+7;

int main () {
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T; cin >> T;
    while (T--) {
        int n, i;
        cin >> n;
        int a [n];
        for (i = 0; i < n; i++) {
            cin >> a [i];
        }

        for (i = n-1; i > 0; i--) {
            if (a [i] >= 0) continue;
            for (int j = i-1; j >= 0; j--) {
                if (a [j] > 0) {
                    ll ff = a [i];
                    a [i]+=min (a [j], a [i]*-1);
                    a [j]-=min (a [j], ff*-1);
                    break;
                }
            }
        }
        int ans = 0;
        for (i = 0; i < n; i++) {
            if (a [i] > 0) ans+=a [i];
        }
        cout << ans << endl;
    }
    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#define  PB push_back
#define  pB pop_back
#define  MP make_pair
#define  endl "\n"
#define  pi 3.14159265358979323846
using ll = long long;
using namespace std;
const int INF = 1e9;
const int N = 2e5+5;
const ll MOD = 1e9+7;

int main () {
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t; cin >> t;
    while (t--) {
        int n, i;
        cin >> n;
        ll a [n];
        for (i = 0; i < n; i++) {
            cin >> a [i];
        }
        for (i = n-1; i > 0; i--) {
            if (a [i] >= 0) continue;
            for (int j = i-1; j >= 0; j--) {
                if (a [j] > 0) {
                    ll ff = a [i]*(-1);
                    a [i]+=min (a [j], ff);
                    a [j]-=min (a [j], ff);
                    if (a [i] == 0) break;
                }
            }
        }
        ll ans = 0LL;
        for (i = 0; i < n; i++) {
            if (a [i] < 0) a [i] = 0;
            ans+=(ll)a [i];
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#define  PB push_back
#define  pB pop_back
#define  MP make_pair
#define  endl "\n"
#define  pi 3.14159265358979323846
using ll = long long;
using namespace std;
const int INF = 1e9;
const int N = 2e5+5;
const ll MOD = 1e9+7;

int main () {
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T; cin >> T;
    while (T--) {
        ll n, i;
        cin >> n;
        ll a [n];
        for (i = 0; i < n; i++) {
            cin >> a [i];
        }

        for (i = n-1; i > 0LL; i--) {
            if (a [i] >= 0LL) continue;
            for (int j = i-1; j >= 0LL; j--) {
                if (a [j] > 0LL) {
                    ll ff = a [i];
                    a [i]+=min (a [j], a [i]*-1LL);
                    a [j]-=min (a [j], ff*-1LL);
                    break;
                }
            }
        }
        ll ans = 0;
        for (i = 0; i < n; i++) {
            if (a [i] > 0) ans+=a [i];
        }
        cout << ans << endl;
    }
    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#define  PB push_back
#define  pB pop_back
#define  MP make_pair
#define  endl "\n"
#define  pi 3.14159265358979323846
using ll = long long;
using namespace std;
const int INF = 1e9;
const int N = 2e5+5;
const ll MOD = 1e9+7;

int main () {
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T; cin >> T;
    while (T--) {
        int n, i;
        cin >> n;
        int a [n];
        for (i = 0; i < n; i++) {
            cin >> a [i];
        }

        for (i = n-1; i > 0; i--) {
            if (a [i] >= 0) continue;
            for (int j = i-1; j >= 0; j--) {
                if (a [j] > 0) {
                    int ff = a [i]*-1;
                    a [i]+=min (a [j], a [i]*-1);
                    a [j]-=min (a [j], ff);
                    break;
                }
            }
        }
        int ans = 0;
        for (i = 0; i < n; i++) {
            if (a [i] > 0) ans+=a [i];
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#define  PB push_back
#define  pB pop_back
#define  MP make_pair
#define  endl "\n"
#define  pi 3.14159265358979323846
using ll = long long;
using namespace std;
const int INF = 1e9;
const int N = 2e5+5;
const ll MOD = 1e9+7;

int main () {
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T; cin >> T;
    while (T--) {
        int n, i;
        cin >> n;
        int a [n];
        for (i = 0; i < n; i++) {
            cin >> a [i];
        }

        for (i = n-1; i > 0; i--) {
            if (a [i] >= 0) continue;
            for (int j = i-1; j >= 0; j--) {
                if (a [j] > 0) {
                    int ff = a [i]*-1;
                    a [i]+=min (a [j], a [i]*-1);
                    a [j]-=min (a [j], ff);
                    break;
                }
            }
        }
        ll ans = 0;
        for (i = 0; i < n; i++) {
            if (a [i] > 0) ans+=(ll)a [i];
        }
        cout << ans << endl;
    }
    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#define  PB push_back
#define  pB pop_back
#define  MP make_pair
#define  endl "\n"
#define  pi 3.14159265358979323846
using ll = long long;
using namespace std;
const int INF = 1e9;
const int N = 2e5+5;
const ll MOD = 1e9+7;

int main () {
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t; cin >> t;
    while (t--) {
        int n, i, j;
        cin >> n;
        ll a [n];
        for (i = 0; i < n; i++) {
            cin >> a [i];
        }
        i = n-1;
        while (a [i] >= 0) i--;
        j = i-1;
        for (; i > 0; i--) {
            if (a [i] >= 0) continue;
            for (; j >= 0; j--) {
                if (a [j] > 0&&j < i) {
                    ll ff = a [i]*(-1);
                    a [i]+=min (a [j], ff);
                    a [j]-=min (a [j], ff);
                    if (a [i] == 0) break;
                }
            }
        }
        ll ans = 0LL;
        for (i = 0; i < n; i++) {
            if (a [i] < 0) a [i] = 0;
            ans+=(ll)a [i];
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#define  PB push_back
#define  pB pop_back
#define  MP make_pair
#define  endl "\n"
#define  pi 3.14159265358979323846
using ll = long long;
using namespace std;
const int INF = 1e9;
const int N = 2e5+5;
const ll MOD = 1e9+7;

int main () {
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T; cin >> T;
    while (T--) {
        int n, i;
        cin >> n;
        int a [n];
        for (i = 0; i < n; i++) {
            cin >> a [i];
        }

        for (i = n-1; i > 0; i--) {
            if (a [i] >= 0) continue;
            for (int j = i-1; j >= 0; j--) {
                if (a [j] > 0) {
                    int ff = a [i]*(-1);
                    a [i]+=min (a [j], ff);
                    a [j]-=min (a [j], ff);
                    break;
                }
            }
        }
        ll ans = 0LL;
        for (i = 0; i < n; i++) {
            if (a [i] > 0) ans+=(ll)a [i];
        }
        cout << ans << endl;
    }
    return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#define  PB push_back
#define  pB pop_back
#define  MP make_pair
#define  endl "\n"
#define  pi 3.14159265358979323846
using ll = long long;
using namespace std;
const int INF = 1e9;
const int N = 2e5+5;
const ll MOD = 1e9+7;

int main () {
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T; cin >> T;
    while (T--) {
        ll n, i;
        cin >> n;
        ll a [n];
        for (i = 0; i < n; i++) {
            cin >> a [i];
        }

        for (i = n-1; i > 0; i--) {
            if (a [i] >= 0) continue;
            for (int j = i-1; j >= 0; j--) {
                if (a [j] > 0) {
                    ll ff = a [i];
                    a [i]+=min (a [j], a [i]*-1);
                    a [j]-=min (a [j], ff*-1);
                    break;
                }
            }
        }
        ll ans = 0;
        for (i = 0; i < n; i++) {
            if (a [i] > 0) ans+=a [i];
        }
        cout << ans << endl;
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#define  PB push_back
#define  pB pop_back
#define  MP make_pair
#define  endl "\n"
#define  pi 3.14159265358979323846
using ll = long long;
using namespace std;
const int INF = 1e9;
const int N = 2e5+5;
const ll MOD = 1e9+7;

int main () {
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t; cin >> t;
    while (t--) {
        int n, i;
        cin >> n;
        ll a [n];
        for (i = 0; i < n; i++) {
            cin >> a [i];
        }
        ll mm = a [n-1];
        for (i = n-2; i >= 0; i--) {
            a [i]+=a [i+1];
            if (a [i] > mm) mm = a [i];
        }
        cout << mm << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#define  PB push_back
#define  pB pop_back
#define  MP make_pair
#define  endl "\n"
#define  pi 3.14159265358979323846
using ll = long long;
using namespace std;
const int INF = 1e9;
const int N = 2e5+5;
const ll MOD = 1e9+7;

int main () {
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T; cin >> T;
    while (T--) {
        int n, i;
        cin >> n;
        ll a [n];
        for (i = 0; i < n; i++) {
            cin >> a [i];
        }

        for (i = n-1; i > 0; i--) {
            if (a [i] >= 0LL) continue;
            for (int j = i-1; j >= 0; j--) {
                if (a [j] > 0LL) {
                    ll ff = a [i];
                    a [i]+=min (a [j], a [i]*-1LL);
                    a [j]-=min (a [j], ff*-1LL);
                    break;
                }
            }
        }
        ll ans = 0;
        for (i = 0; i < n; i++) {
            if (a [i] > 0) ans+=a [i];
        }
        cout << ans << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"

const int N = 2e5 + 1;

signed main(){
  IOS;
  int t;
  cin >> t;
  while (t--){
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i ++)
      cin >> a[i];
    if (n == 1){
      cout << 0 << endl;
      continue;
    }
    vector<pair<int, int> > v;
    vector<int> ans;

    int sum = 0;
    for (int i = 0; i < n; i ++)
      if (a[i] < 0){
         sum += a[i];
      }
      else{
        bool flag = 0;
        if (!sum)continue;
        v.push_back({i - 1, sum});
        while (a[i] > 0)
          i++, flag = 1;
        if (flag) i--;
        sum = 0;
      }

    if (a[n - 1] < 0)
      v.push_back({n - 1, sum});

    sum = 0;
    for (int i = 0; i < n; i ++)
      if (a[i] > 0){
        sum += a[i];
      }
      else{
        if (!sum) continue;
        bool flag = 0;
        v.push_back({i - 1, sum});
        while (a[i] < 0)
          i ++, flag = 1;
        if (flag) i--;
        sum = 0;
      }

     if (a[n - 1] > 0)
      v.push_back({n - 1, sum});

    sort(v.begin(), v.end());

    for (auto i: v)
      ans.push_back(i.second);

      //ans.push_back(0);

    int res = 0, sz = ans.size();

   /* for (auto i: ans)
      cout << i << " ";
    cout << endl;*/

    for (int i = 0; i < sz - 1; i ++)
      if (ans[i] > 0)
      if (ans[i] - abs(ans[i + 1]) > 0)
        res += ans[i] - abs(ans[i + 1]);

    //cout << res << endl;

       if (ans[sz - 1] > 0)
        res += (abs(ans[sz - 1]));

   cout << res << endl;

  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"

const int N = 2e5 + 1;

signed main(){
  IOS;
  int t;
  cin >> t;
  while (t--){
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i ++)
      cin >> a[i];
   int cnt = 0;
   for (int i = 0; i < n; i ++)
    if (a[i] == 0)
      cnt++;
    if (cnt == n){
      cout << 0 << endl;
      continue;
    }
    vector<pair<int, int> > v;
    vector<int> ans;

    int sum = 0;
    for (int i = 0; i < n; i ++)
      if (a[i] <= 0){
         sum += a[i];
      }
      else{
        bool flag = 0;
        v.push_back({i - 1, sum});
        while (a[i] > 0)
          i++, flag = 1;
        if (flag) i--;
        sum = 0;
      }

    if (a[n - 1] < 0)
      v.push_back({n - 1, sum});

    sum = 0;
    for (int i = 0; i < n; i ++)
      if (a[i] >= 0){
        sum += a[i];
      }
      else{

        bool flag = 0;
        v.push_back({i - 1, sum});
        while (a[i] < 0)
          i ++, flag = 1;
        if (flag) i--;
        sum = 0;
      }

     if (a[n - 1] > 0)
      v.push_back({n - 1, sum});

    sort(v.begin(), v.end());

    for (auto i: v)
      ans.push_back(i.second);

      ans.push_back(0);

    int res = 0, sz = ans.size();

    /*for (auto i: ans)
      cout << i << " ";
    cout << endl;
*/
    for (int i = 0; i < sz - 1; i ++)
      if (ans[i] > 0)
      if (ans[i] - abs(ans[i + 1]) > 0)
        res += ans[i] - abs(ans[i + 1]);

    cout << res << endl;
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"

const int N = 2e5 + 1;

signed main(){
  IOS;
  int t;
  cin >> t;
  while (t--){
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i ++)
      cin >> a[i];
    if (n == 1){
      cout << 0 << endl;
      continue;
    }
    vector<pair<int, int> > v;
    vector<int> ans;

    int sum = 0;
    for (int i = 0; i < n; i ++)
      if (a[i] < 0){
         sum += a[i];
      }
      else{
        bool flag = 0;
        if (!sum)continue;
        v.push_back({i - 1, sum});
        while (a[i] > 0)
          i++, flag = 1;
        if (flag) i--;
        sum = 0;
      }

    if (a[n - 1] < 0)
      v.push_back({n - 1, sum});

    sum = 0;
    for (int i = 0; i < n; i ++)
      if (a[i] > 0){
        sum += a[i];
      }
      else{
        if (!sum) continue;
        bool flag = 0;
        v.push_back({i - 1, sum});
        while (a[i] < 0)
          i ++, flag = 1;
        if (flag) i--;
        sum = 0;
      }

     if (a[n - 1] > 0)
      v.push_back({n - 1, sum});

    sort(v.begin(), v.end());

    for (auto i: v)
      ans.push_back(i.second);

      //ans.push_back(0);

    int res = 0, sz = ans.size();

    /*for (auto i: ans)
      cout << i << " ";
    cout << endl;
*/
    for (int i = 0; i < sz - 1; i ++)
      if (ans[i] > 0)
      if (ans[i] - abs(ans[i + 1]) > 0)
        res += ans[i] - abs(ans[i + 1]);

    if (ans[sz - 1] > 0)
    res += ans[sz - 1];

    cout << res << endl;
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"

const int N = 2e5 + 1;

signed main(){
  IOS;
  int t;
  cin >> t;
  while (t--){
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i ++)
      cin >> a[i];

    vector<pair<int, int> > v;
    vector<int> ans;

    int sum = 0;
    for (int i = 0; i < n; i ++)
      if (a[i] < 0){
         sum += a[i];
      }
      else{
        bool flag = 0;
        v.push_back({i - 1, sum});
        while (a[i] > 0)
          i++, flag = 1;
        if (flag) i--;
        sum = 0;
      }

    if (a[n - 1] < 0)
      v.push_back({n - 1, sum});

    sum = 0;
    for (int i = 0; i < n; i ++)
      if (a[i] > 0){
        sum += a[i];
      }
      else{
        bool flag = 0;
        v.push_back({i - 1, sum});
        while (a[i] < 0)
          i ++, flag = 1;
        if (flag) i--;
        sum = 0;
      }

     if (a[n - 1] > 0)
      v.push_back({n - 1, sum});

    sort(v.begin(), v.end());

    for (auto i: v)
      ans.push_back(i.second);

      //ans.push_back(0);

    int res = 0, sz = ans.size();

    /*for (auto i: ans)
      cout << i << " ";
    cout << endl;*/

    for (int i = 1; i < sz - 1; i ++)
      if (ans[i] > 0)
      if (ans[i] - abs(ans[i + 1]) > 0)
        res += ans[i] - abs(ans[i + 1]);

    //cout << res << endl;

       if (ans[sz - 1] > 0)
        res += (abs(ans[sz - 1]));

   cout << res << endl;

  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"

const int N = 2e5 + 1;

signed main(){
  IOS;
  int t;
  cin >> t;
  while (t--){
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i ++)
      cin >> a[i];
   int cnt = 0;
   for (int i = 0; i < n; i ++)
    if (a[i] == 0)
      cnt++;
    if (cnt == n){
      cout << 0 << endl;
      continue;
    }
    vector<pair<int, int> > v;
    vector<int> ans;

    int sum = 0;
    for (int i = 0; i < n; i ++)
      if (a[i] < 0){
         sum += a[i];
      }
      else{
        bool flag = 0;
        if (!sum)continue;
        v.push_back({i - 1, sum});
        while (a[i] > 0)
          i++, flag = 1;
        if (flag) i--;
        sum = 0;
      }

    if (a[n - 1] < 0)
      v.push_back({n - 1, sum});

    sum = 0;
    for (int i = 0; i < n; i ++)
      if (a[i] > 0){
        sum += a[i];
      }
      else{
        if (!sum) continue;
        bool flag = 0;
        v.push_back({i - 1, sum});
        while (a[i] < 0)
          i ++, flag = 1;
        if (flag) i--;
        sum = 0;
      }

     if (a[n - 1] > 0)
      v.push_back({n - 1, sum});

    sort(v.begin(), v.end());

    for (auto i: v)
      ans.push_back(i.second);

      //ans.push_back(0);

    int res = 0, sz = ans.size();

    /*for (auto i: ans)
      cout << i << " ";
    cout << endl;
*/
    for (int i = 0; i < sz - 1; i ++)
      if (ans[i] > 0)
      if (ans[i] - abs(ans[i + 1]) > 0)
        res += ans[i] - abs(ans[i + 1]);

    if (ans[sz - 1] > 0)
    res += ans[sz - 1];

    cout << res << endl;
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"

const int N = 2e5 + 1;

signed main(){
  IOS;
  int t;
  cin >> t;
  while (t--){
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i ++)
      cin >> a[i];
    if (n == 1){
      cout << 0 << endl;
      continue;
    }
    vector<pair<int, int> > v;
    vector<int> ans;

    int sum = 0;
    for (int i = 0; i < n; i ++)
      if (a[i] < 0){
         sum += a[i];
      }
      else{
        bool flag = 0;
        if (!sum)continue;
        v.push_back({i - 1, sum});
        while (a[i] > 0)
          i++, flag = 1;
        if (flag) i--;
        sum = 0;
      }

    if (a[n - 1] < 0)
      v.push_back({n - 1, sum});

    sum = 0;
    for (int i = 0; i < n; i ++)
      if (a[i] > 0){
        sum += a[i];
      }
      else{
        if (!sum) continue;
        bool flag = 0;
        v.push_back({i - 1, sum});
        while (a[i] < 0)
          i ++, flag = 1;
        if (flag) i--;
        sum = 0;
      }

     if (a[n - 1] > 0)
      v.push_back({n - 1, sum});

    sort(v.begin(), v.end());

    for (auto i: v)
      ans.push_back(i.second);

      //ans.push_back(0);

    int res = 0, sz = ans.size();

    for (auto i: ans)
      cout << i << " ";
    cout << endl;

    for (int i = 0; i < sz - 1; i ++)
      if (ans[i] > 0)
      if (ans[i] - abs(ans[i + 1]) > 0)
        res += ans[i] - abs(ans[i + 1]);

    if (ans[sz - 1] > 0)
    res += ans[sz - 1];

    cout << res << endl;
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"

const int N = 2e5 + 1;

signed main(){
  IOS;
  int t;
  cin >> t;
  while (t--){
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i ++)
      cin >> a[i];
   int mx = 0;
   for (int i = 0; i < n; i ++)
   mx = max(0LL, mx + a[i]);

   cout << mx << endl;

  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define first F
#define second S
#define push_back PB
#define pop_back POB
#define make_pair MP
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define cloop(i,a,b,d) for(int i = a ; i < b ; i += d)
#define rloop(i,a,b) for(int i = a ; i >= b ; i--)
#define crloop(i,a,b,d) for(int i = a ; i >= b ; i -= d)

typedef long long int int64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int64> vint64;
typedef vector<vint64> vvint64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pint64int64;

int main(){
    ios::sync_with_stdio(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int t, n, e;
    int64 c, s;
    cin >> t;
    while(t--) {
        c = 0;
        s = 0;
        cin >> n;
        loop(i, 0, n) {
            cin >> e;
            if(e < 0) {
                int t = e + s;
                if(t < 0) {
                    c = c - t;
                } else {
                    s += e;
                }
            } else {
                s += e;
            }
        }
        cout << c << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define first F
#define second S
#define push_back PB
#define pop_back POB
#define make_pair MP
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define cloop(i,a,b,d) for(int i = a ; i < b ; i += d)
#define rloop(i,a,b) for(int i = a ; i >= b ; i--)
#define crloop(i,a,b,d) for(int i = a ; i >= b ; i -= d)

typedef long long int int64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int64> vint64;
typedef vector<vint64> vvint64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pint64int64;

int main(){
    ios::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int64 t, n, e;
    int64 c, s;
    cin >> t;
    while(t--) {
        c = 0;
        s = 0;
        cin >> n;
        for(int i = 0 ; i < n ; i++){
            cin >> e;
            if(e < 0) {
                s += e;
                if(s < 0) {
                    // cout << s << endl;
                    c = c - s;
                    s = 0;
                }
            } else {
                s += e;
            }
        }
        cout << c << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define first F
#define second S
#define push_back PB
#define pop_back POB
#define make_pair MP
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define cloop(i,a,b,d) for(int i = a ; i < b ; i += d)
#define rloop(i,a,b) for(int i = a ; i >= b ; i--)
#define crloop(i,a,b,d) for(int i = a ; i >= b ; i -= d)

typedef long long int int64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int64> vint64;
typedef vector<vint64> vvint64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pint64int64;

int main(){
    ios::sync_with_stdio(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int64 t, n, e;
    int64 c, s;
    cin >> t;
    while(t--) {
        c = 0;
        s = 0;
        cin >> n;
        for(int i = 0 ; i < n ;i++){
            cin >> e;
            if(e < 0) {
                s += e;
                if(s < 0) {
                    // cout << s << endl;
                    c = c - s;
                    s = 0;
                }
            } else {
                s += e;
            }
        }
        cout << c << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define first F
#define second S
#define push_back PB
#define pop_back POB
#define make_pair MP
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define cloop(i,a,b,d) for(int i = a ; i < b ; i += d)
#define rloop(i,a,b) for(int i = a ; i >= b ; i--)
#define crloop(i,a,b,d) for(int i = a ; i >= b ; i -= d)

typedef long long int int64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int64> vint64;
typedef vector<vint64> vvint64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pint64int64;

int main(){
    ios::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t, n, e;
    int64 c, s;
    cin >> t;
    while(t--) {
        c = 0;
        s = 0;
        cin >> n;
        loop(i, 0, n) {
            cin >> e;
            if(e < 0) {
                int t = e + s;
                if(t < 0) {
                    c = c - t;
                } else {
                    s += e;
                }
            } else {
                s += e;
            }
        }
        cout << c << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define first F
#define second S
#define push_back PB
#define pop_back POB
#define make_pair MP
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define cloop(i,a,b,d) for(int i = a ; i < b ; i += d)
#define rloop(i,a,b) for(int i = a ; i >= b ; i--)
#define crloop(i,a,b,d) for(int i = a ; i >= b ; i -= d)

typedef long long int int64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int64> vint64;
typedef vector<vint64> vvint64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pint64int64;

int main(){
    ios::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int64 t, n, e;
    int64 c, s;
    cin >> t;
    while(t--) {
        c = 0;
        s = 0;
        cin >> n;
        loop(i, 0, n) {
            cin >> e;
            if(e < 0) {
                s += e;
                if(s < 0) {
                    c = c - s;
                }
            } else {
                s += e;
            }
        }
        cout << c << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define first F
#define second S
#define push_back PB
#define pop_back POB
#define make_pair MP
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define cloop(i,a,b,d) for(int i = a ; i < b ; i += d)
#define rloop(i,a,b) for(int i = a ; i >= b ; i--)
#define crloop(i,a,b,d) for(int i = a ; i >= b ; i -= d)

typedef long long int int64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int64> vint64;
typedef vector<vint64> vvint64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pint64int64;

int main(){
    ios::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int6 t, n, e;
    int64 c, s;
    cin >> t;
    while(t--) {
        c = 0;
        s = 0;
        cin >> n;
        loop(i, 0, n) {
            cin >> e;
            if(e < 0) {
                s += e;
                if(s < 0) {
                    c = c - s;
                }
            } else {
                s += e;
            }
        }
        cout << c << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define first F
#define second S
#define push_back PB
#define pop_back POB
#define make_pair MP
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define cloop(i,a,b,d) for(int i = a ; i < b ; i += d)
#define rloop(i,a,b) for(int i = a ; i >= b ; i--)
#define crloop(i,a,b,d) for(int i = a ; i >= b ; i -= d)

typedef long long int int64;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int64> vint64;
typedef vector<vint64> vvint64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pint64int64;

int main(){
    ios::sync_with_stdio(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int64 t, n, e;
    int64 c, s;
    cin >> t;
    while(t--) {
        c = 0;
        s = 0;
        cin >> n;
        loop(i, 0, n) {
            cin >> e;
            if(e < 0) {
                int t = e + s;
                if(t < 0) {
                    c = c - t;
                } else {
                    s += e;
                }
            } else {
                s += e;
            }
        }
        cout << c << endl;
    }
    return 0;
}


// Problem : B. Array Cancellation
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : A. Permutation Forgery
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/0
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//traverse a map  int reverse use mi::reverse_iterator it=map.rbegin();
//or sue auto it=map.rbegin()
// stoll ->stoi for ll
//(ll)sqrt
//atoi(string.c_str())
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll                 long long
#define pb               push_back
#define mp 		      make_pair
#define pii               pair<ll,ll>
#define vi                vector<ll>
#define vvi              vector<vector<ll>>
#define vii               vector<pii>
#define mi               map<ll,ll>
#define mii              map<pii,ll>
#define all(a)           a.begin(),a.end()
#define fi                 first
#define rall(a)          a.rbegin(),a.rend()
#define si                 second
#define sz(x)            (ll)x.size()
#define endl             '\n'
#define mod             1000000007
#define inf                1000000000000000000
#define iinf              -1000000000000000000
#define puts(n)		   cout<<n<<endl;
#define bas               cout<<endl
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define mset(m,v)    memset(m,v,sizeof(m))
#define tej                ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main() {
	int n;
	cin>>n;
	while(n--){
ll a;
cin>>a;
vi v(a);
rep(i,0,a)cin>>v[i];
ll ans=0,o=0;
int i=0,r=0;
     while(i<a && v[i]<=0){ans+=abs(v[i]);i++;}
while(i<a-1){
     o=r;
     while(i<a-1 && v[i]>0){o+=v[i];i++;}
     while(i<a-1&&v[i]<=0){
          o+=v[i];i++;
     }if(o<0){ans+=abs(o);r=o;}
     else r=o;

}

cout<<ans<<endl;

	}
	return 0;}


// Problem : B. Array Cancellation
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : A. Permutation Forgery
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/0
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//traverse a map  int reverse use mi::reverse_iterator it=map.rbegin();
//or sue auto it=map.rbegin()
// stoll ->stoi for ll
//(ll)sqrt
//atoi(string.c_str())
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll                 long long
#define pb               push_back
#define mp 		      make_pair
#define pii               pair<ll,ll>
#define vi                vector<ll>
#define vvi              vector<vector<ll>>
#define vii               vector<pii>
#define mi               map<ll,ll>
#define mii              map<pii,ll>
#define all(a)           a.begin(),a.end()
#define fi                 first
#define rall(a)          a.rbegin(),a.rend()
#define si                 second
#define sz(x)            (ll)x.size()
#define endl             '\n'
#define mod             1000000007
#define inf                1000000000000000000
#define iinf              -1000000000000000000
#define puts(n)		   cout<<n<<endl;
#define bas               cout<<endl
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define mset(m,v)    memset(m,v,sizeof(m))
#define tej                ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main() {
	int n;
	cin>>n;
	while(n--){
ll a;
cin>>a;
vi v(a);
rep(i,0,a)cin>>v[i];
ll ans=0,o=0;
int i=0,r=0;
     while(v[i]<0){ans+=abs(v[i]);i++;}
while(i<a){
     o=v[i]+r;i++;
     while(v[i]<0){
          o+=v[i];i++;
     }if(o<0){ans+=abs(o);r=o;}
     else r=o;

}

cout<<ans<<endl;

	}
	return 0;}


// Problem : B. Array Cancellation
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : A. Permutation Forgery
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/0
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//traverse a map  int reverse use mi::reverse_iterator it=map.rbegin();
//or sue auto it=map.rbegin()
// stoll ->stoi for ll
//(ll)sqrt
//atoi(string.c_str())
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll                 long long
#define pb               push_back
#define mp 		      make_pair
#define pii               pair<ll,ll>
#define vi                vector<ll>
#define vvi              vector<vector<ll>>
#define vii               vector<pii>
#define mi               map<ll,ll>
#define mii              map<pii,ll>
#define all(a)           a.begin(),a.end()
#define fi                 first
#define rall(a)          a.rbegin(),a.rend()
#define si                 second
#define sz(x)            (ll)x.size()
#define endl             '\n'
#define mod             1000000007
#define inf                1000000000000000000
#define iinf              -1000000000000000000
#define puts(n)		   cout<<n<<endl;
#define bas               cout<<endl
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define mset(m,v)    memset(m,v,sizeof(m))
#define tej                ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main() {
	int n;
	cin>>n;
	while(n--){
ll a;
cin>>a;
vi v(a);
rep(i,0,a)cin>>v[i];
ll ans=0,o=0;
int i=0,r=0;
     while(v[i]<0){ans+=abs(v[i]);i++;}
while(i<a-1){
     o=v[i]+r;i++;
     while(v[i]<0){
          o+=v[i];i++;
     }if(o<0){ans+=abs(o);r=o;}
     else r=o;

}

cout<<ans<<endl;

	}
	return 0;}


// Problem : B. Array Cancellation
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : A. Permutation Forgery
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/0
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//traverse a map  int reverse use mi::reverse_iterator it=map.rbegin();
//or sue auto it=map.rbegin()
// stoll ->stoi for ll
//(ll)sqrt
//atoi(string.c_str())
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll                 long long
#define pb               push_back
#define mp 		      make_pair
#define pii               pair<ll,ll>
#define vi                vector<ll>
#define vvi              vector<vector<ll>>
#define vii               vector<pii>
#define mi               map<ll,ll>
#define mii              map<pii,ll>
#define all(a)           a.begin(),a.end()
#define fi                 first
#define rall(a)          a.rbegin(),a.rend()
#define si                 second
#define sz(x)            (ll)x.size()
#define endl             '\n'
#define mod             1000000007
#define inf                1000000000000000000
#define iinf              -1000000000000000000
#define puts(n)		   cout<<n<<endl;
#define bas               cout<<endl
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define mset(m,v)    memset(m,v,sizeof(m))
#define tej                ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main() {
	int n;
	cin>>n;
	while(n--){
ll a;
cin>>a;
vi v(a);
rep(i,0,a)cin>>v[i];
vi v1(a);
ll ans=v[0],o=0;
reverse(all(v));
v1[0]=v[0];
rep(i,1,a){
     v1[i]=v1[i-1]+v[i];
}
cout<<*max_element(all(v1))<<endl;

	}
	return 0;}


// Problem : B. Array Cancellation
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : A. Permutation Forgery
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/0
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//traverse a map  int reverse use mi::reverse_iterator it=map.rbegin();
//or sue auto it=map.rbegin()
// stoll ->stoi for ll
//(ll)sqrt
//atoi(string.c_str())
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll                 long long
#define pb               push_back
#define mp 		      make_pair
#define pii               pair<ll,ll>
#define vi                vector<ll>
#define vvi              vector<vector<ll>>
#define vii               vector<pii>
#define mi               map<ll,ll>
#define mii              map<pii,ll>
#define all(a)           a.begin(),a.end()
#define fi                 first
#define rall(a)          a.rbegin(),a.rend()
#define si                 second
#define sz(x)            (ll)x.size()
#define endl             '\n'
#define mod             1000000007
#define inf                1000000000000000000
#define iinf              -1000000000000000000
#define puts(n)		   cout<<n<<endl;
#define bas               cout<<endl
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define mset(m,v)    memset(m,v,sizeof(m))
#define tej                ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main() {
	int n;
	cin>>n;
	while(n--){
ll a;
cin>>a;
vi v(a);
rep(i,0,a)cin>>v[i];
ll ans=0,o=0;
int i=0,r=0;
     while(v[i]<=0){ans+=abs(v[i]);i++;}
while(i<a){
     o=v[i]+r;i++;
     while(v[i]<0){
          o+=v[i];i++;
     }if(o<0){ans+=abs(o);r=o;}
     else r=o;

}

cout<<ans<<endl;

	}
	return 0;}


// Problem : B. Array Cancellation
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : A. Permutation Forgery
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/0
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//traverse a map  int reverse use mi::reverse_iterator it=map.rbegin();
//or sue auto it=map.rbegin()
// stoll ->stoi for ll
//(ll)sqrt
//atoi(string.c_str())
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll                 long long
#define pb               push_back
#define mp 		      make_pair
#define pii               pair<ll,ll>
#define vi                vector<ll>
#define vvi              vector<vector<ll>>
#define vii               vector<pii>
#define mi               map<ll,ll>
#define mii              map<pii,ll>
#define all(a)           a.begin(),a.end()
#define fi                 first
#define rall(a)          a.rbegin(),a.rend()
#define si                 second
#define sz(x)            (ll)x.size()
#define endl             '\n'
#define mod             1000000007
#define inf                1000000000000000000
#define iinf              -1000000000000000000
#define puts(n)		   cout<<n<<endl;
#define bas               cout<<endl
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define mset(m,v)    memset(m,v,sizeof(m))
#define tej                ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main() {
	int n;
	cin>>n;
	while(n--){
ll a;
cin>>a;
vi v(a);
rep(i,0,a)cin>>v[i];
ll ans=0,o=0;
int i=0,r=0;
     while(i<a && v[i]<=0){ans+=abs(v[i]);i++;}
while(i<a){
     o=v[i]+r;i++;
     while(v[i]<=0){
          o+=v[i];i++;
     }if(o<0){ans+=abs(o);r=o;}
     else r=o;

}

cout<<ans<<endl;

	}
	return 0;}


// Problem : B. Array Cancellation
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : A. Permutation Forgery
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/0
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//traverse a map  int reverse use mi::reverse_iterator it=map.rbegin();
//or sue auto it=map.rbegin()
// stoll ->stoi for ll
//(ll)sqrt
//atoi(string.c_str())
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll                 long long
#define pb               push_back
#define mp 		      make_pair
#define pii               pair<ll,ll>
#define vi                vector<ll>
#define vvi              vector<vector<ll>>
#define vii               vector<pii>
#define mi               map<ll,ll>
#define mii              map<pii,ll>
#define all(a)           a.begin(),a.end()
#define fi                 first
#define rall(a)          a.rbegin(),a.rend()
#define si                 second
#define sz(x)            (ll)x.size()
#define endl             '\n'
#define mod             1000000007
#define inf                1000000000000000000
#define iinf              -1000000000000000000
#define puts(n)		   cout<<n<<endl;
#define bas               cout<<endl
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define mset(m,v)    memset(m,v,sizeof(m))
#define tej                ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main() {
	int n;
	cin>>n;
	while(n--){
ll a;
cin>>a;
vi v(a);
rep(i,0,a)cin>>v[i];
ll ans=0,o=0;
int i=0;
     while(v[i]<0){ans+=abs(v[i]);i++;}
while(i<a-1){
     o=v[i];i++;
     while(v[i]<0){
          o+=v[i];i++;
     }if(o<0)ans+=abs(o);

}

cout<<ans<<endl;

	}
	return 0;}


// Problem : B. Array Cancellation
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : A. Permutation Forgery
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/0
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//traverse a map  int reverse use mi::reverse_iterator it=map.rbegin();
//or sue auto it=map.rbegin()
// stoll ->stoi for ll
//(ll)sqrt
//atoi(string.c_str())
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll                 long long
#define pb               push_back
#define mp 		      make_pair
#define pii               pair<ll,ll>
#define vi                vector<ll>
#define vvi              vector<vector<ll>>
#define vii               vector<pii>
#define mi               map<ll,ll>
#define mii              map<pii,ll>
#define all(a)           a.begin(),a.end()
#define fi                 first
#define rall(a)          a.rbegin(),a.rend()
#define si                 second
#define sz(x)            (ll)x.size()
#define endl             '\n'
#define mod             1000000007
#define inf                1000000000000000000
#define iinf              -1000000000000000000
#define puts(n)		   cout<<n<<endl;
#define bas               cout<<endl
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define mset(m,v)    memset(m,v,sizeof(m))
#define tej                ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main() {
	int n;
	cin>>n;
	while(n--){
ll a;
cin>>a;
vi v(a);
rep(i,0,a)cin>>v[i];
ll ans=0,o=0;
int i=0,r=0;
     while(v[i]<0){ans+=abs(v[i]);i++;}
while(i<a-1){
     o=v[i]+r;i++;
     while(v[i]<0){
          o+=v[i];i++;
     }if(o<0)ans+=abs(o);
     else r=o;

}

cout<<ans<<endl;

	}
	return 0;}


// Problem : B. Array Cancellation
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : A. Permutation Forgery
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/0
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//traverse a map  int reverse use mi::reverse_iterator it=map.rbegin();
//or sue auto it=map.rbegin()
// stoll ->stoi for ll
//(ll)sqrt
//atoi(string.c_str())
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll                 long long
#define pb               push_back
#define mp 		      make_pair
#define pii               pair<ll,ll>
#define vi                vector<ll>
#define vvi              vector<vector<ll>>
#define vii               vector<pii>
#define mi               map<ll,ll>
#define mii              map<pii,ll>
#define all(a)           a.begin(),a.end()
#define fi                 first
#define rall(a)          a.rbegin(),a.rend()
#define si                 second
#define sz(x)            (ll)x.size()
#define endl             '\n'
#define mod             1000000007
#define inf                1000000000000000000
#define iinf              -1000000000000000000
#define puts(n)		   cout<<n<<endl;
#define bas               cout<<endl
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define mset(m,v)    memset(m,v,sizeof(m))
#define tej                ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main() {
	int n;
	cin>>n;
	while(n--){
ll a;
cin>>a;
vi v(a);
rep(i,0,a)cin>>v[i];
ll ans=0,o=0;
int i=0,r=0;
     while(i<a && v[i]<=0){ans+=abs(v[i]);i++;}
while(i<a-1){
     o=r;
     while(v[i]>0){o+=v[i];i++;}
     while(v[i]<=0){
          o+=v[i];i++;
     }if(o<0){ans+=abs(o);r=o;}
     else r=o;

}

cout<<ans<<endl;

	}
	return 0;}


// Problem : B. Array Cancellation
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : A. Permutation Forgery
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/0
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//traverse a map  int reverse use mi::reverse_iterator it=map.rbegin();
//or sue auto it=map.rbegin()
// stoll ->stoi for ll
//(ll)sqrt
//atoi(string.c_str())
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll                 long long
#define pb               push_back
#define mp 		      make_pair
#define pii               pair<ll,ll>
#define vi                vector<ll>
#define vvi              vector<vector<ll>>
#define vii               vector<pii>
#define mi               map<ll,ll>
#define mii              map<pii,ll>
#define all(a)           a.begin(),a.end()
#define fi                 first
#define rall(a)          a.rbegin(),a.rend()
#define si                 second
#define sz(x)            (ll)x.size()
#define endl             '\n'
#define mod             1000000007
#define inf                1000000000000000000
#define iinf              -1000000000000000000
#define puts(n)		   cout<<n<<endl;
#define bas               cout<<endl
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define mset(m,v)    memset(m,v,sizeof(m))
#define tej                ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main() {
	int n;
	cin>>n;
	while(n--){
ll a;
cin>>a;
vi v(a);
rep(i,0,a)cin>>v[i];
ll ans=0,o=0;
int i=0,r=0;
     while(i<a && v[i]<=0){ans+=abs(v[i]);i++;}
while(i<a){
     o=v[i]+r;i++;
     while(v[i]<0){
          o+=v[i];i++;
     }if(o<0){ans+=abs(o);r=o;}
     else r=o;

}

cout<<ans<<endl;

	}
	return 0;}


// Problem : B. Array Cancellation
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : A. Permutation Forgery
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/0
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//traverse a map  int reverse use mi::reverse_iterator it=map.rbegin();
//or sue auto it=map.rbegin()
// stoll ->stoi for ll
//(ll)sqrt
//atoi(string.c_str())
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll                 long long
#define pb               push_back
#define mp 		      make_pair
#define pii               pair<ll,ll>
#define vi                vector<ll>
#define vvi              vector<vector<ll>>
#define vii               vector<pii>
#define mi               map<ll,ll>
#define mii              map<pii,ll>
#define all(a)           a.begin(),a.end()
#define fi                 first
#define rall(a)          a.rbegin(),a.rend()
#define si                 second
#define sz(x)            (ll)x.size()
#define endl             '\n'
#define mod             1000000007
#define inf                1000000000000000000
#define iinf              -1000000000000000000
#define puts(n)		   cout<<n<<endl;
#define bas               cout<<endl
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define mset(m,v)    memset(m,v,sizeof(m))
#define tej                ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main() {
	int n;
	cin>>n;
	while(n--){
ll a;
cin>>a;
vi v(a);
rep(i,0,a)cin>>v[i];
ll ans=0,o=0;
int i=0,r=0;
     while(i<a && v[i]<=0){ans+=abs(v[i]);i++;}
while(i<a){
     o=r;
     while(i<a && v[i]>=0){o+=v[i];i++;}
     while(i<a&&v[i]<=0){
          o+=v[i];i++;
     }if(o<0){ans+=abs(o);}
     else r=o;

}

cout<<ans<<endl;

	}
	return 0;}


// Problem : B. Array Cancellation
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : A. Permutation Forgery
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/0
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//traverse a map  int reverse use mi::reverse_iterator it=map.rbegin();
//or sue auto it=map.rbegin()
// stoll ->stoi for ll
//(ll)sqrt
//atoi(string.c_str())
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll                 long long
#define pb               push_back
#define mp 		      make_pair
#define pii               pair<ll,ll>
#define vi                vector<ll>
#define vvi              vector<vector<ll>>
#define vii               vector<pii>
#define mi               map<ll,ll>
#define mii              map<pii,ll>
#define all(a)           a.begin(),a.end()
#define fi                 first
#define rall(a)          a.rbegin(),a.rend()
#define si                 second
#define sz(x)            (ll)x.size()
#define endl             '\n'
#define mod             1000000007
#define inf                1000000000000000000
#define iinf              -1000000000000000000
#define puts(n)		   cout<<n<<endl;
#define bas               cout<<endl
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define mset(m,v)    memset(m,v,sizeof(m))
#define tej                ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main() {
	int n;
	cin>>n;
	while(n--){
ll a;
cin>>a;
vi v(a);
rep(i,0,a)cin>>v[i];
ll ans=0,o=0;
int i=0,r=0;
     while(i<a && v[i]<=0){ans+=abs(v[i]);i++;}
while(i<a){
     o=r;
     while(i<a && v[i]>=0){o+=v[i];i++;}
     while(i<a&&v[i]<=0){
          o+=v[i];i++;
     }if(o<0){ans+=abs(o);r=o;}
     else r=o;

}

cout<<ans<<endl;

	}
	return 0;}


// Problem : B. Array Cancellation
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/B
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : A. Permutation Forgery
// Contest : Codeforces - Codeforces Round #668 (Div. 2)
// URL : https://codeforces.com/contest/1405/problem/0
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//traverse a map  int reverse use mi::reverse_iterator it=map.rbegin();
//or sue auto it=map.rbegin()
// stoll ->stoi for ll
//(ll)sqrt
//atoi(string.c_str())
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll                 long long
#define pb               push_back
#define mp 		      make_pair
#define pii               pair<ll,ll>
#define vi                vector<ll>
#define vvi              vector<vector<ll>>
#define vii               vector<pii>
#define mi               map<ll,ll>
#define mii              map<pii,ll>
#define all(a)           a.begin(),a.end()
#define fi                 first
#define rall(a)          a.rbegin(),a.rend()
#define si                 second
#define sz(x)            (ll)x.size()
#define endl             '\n'
#define mod             1000000007
#define inf                1000000000000000000
#define iinf              -1000000000000000000
#define puts(n)		   cout<<n<<endl;
#define bas               cout<<endl
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define mset(m,v)    memset(m,v,sizeof(m))
#define tej                ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;

int main() {
	int n;
	cin>>n;
	while(n--){
ll a;
cin>>a;
vi v(a);
rep(i,0,a)cin>>v[i];
ll ans=0,o=0;
int i=0,r=0;
     while(i<a && v[i]<=0){ans+=abs(v[i]);i++;}
while(i<a-1){
     o=r;
     while(i<a && v[i]>0){o+=v[i];i++;}
     while(i<a&&v[i]<=0){
          o+=v[i];i++;
     }if(o<0){ans+=abs(o);r=o;}
     else r=o;

}

cout<<ans<<endl;

	}
	return 0;}


//                _
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/
//                  |___/                         |_|
//code by smigwump
//https://codeforces.com/blog/entry/62393 hashing hack protection
//https://codeforces.com/blog/entry/61587 rand() alternatives
//https://codeforces.com/blog/entry/61675 randomized hack protection
//https://en.wikipedia.org/wiki/Fermat's_little_theorem
//https://en.wikipedia.org/wiki/Euler%27s_totient_function
#include <bits/stdc++.h>
typedef long long ll;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)

using namespace std;

int main() {
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	// #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin>>tc;
    while(tc--) {
    	ll n;
        cin>>n;
        vector<ll> a(n,0);
        REP(i,0,n-1) {
            cin>>a[i];
        }
        reverse(all(a));
        PER(i,n-1,1) {
            if(a[i]>0) {
                ll j = i-1;
                while(j>=0) {
                    if(a[j] < 0) {
                        if(abs(a[j])>a[i]) {
                            a[j] += a[i];
                            a[i] = 0;
                        }
                        else {
                            ll temp1 = a[j], temp2 = a[i];
                            a[i] += temp1;
                            a[j] = 0;
                        }
                        break;
                    }
                    else {
                        j--;
                    }
                }
            }
        }
        // for(auto it : a) {
        //     cout<<it<<" ";
        // }
        // cout<<"\n";
        ll ans = 0;
        REP(i,0,n-1) {
            if(a[i]<0) {
                ans+=a[i];
            }
        }
        cout<<(-1*ans)<<"\n";
        //cout<<"\n";
    }
	return 0;
}


//                _
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/
//                  |___/                         |_|
//code by smigwump
//https://codeforces.com/blog/entry/62393 hashing hack protection
//https://codeforces.com/blog/entry/61587 rand() alternatives
//https://codeforces.com/blog/entry/61675 randomized hack protection
//https://en.wikipedia.org/wiki/Fermat's_little_theorem
//https://en.wikipedia.org/wiki/Euler%27s_totient_function
#include <bits/stdc++.h>
typedef long long ll;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)

using namespace std;

int main() {
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	// #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin>>tc;
    while(tc--) {
    	ll n;
        cin>>n;
        vector<ll> a(n,0);
        REP(i,0,n-1) {
            cin>>a[i];
        }
        //answer is the max suffix sum ..... THINK!!!!!!!!!
        ll mx = 0;
        REP(i,0,n-1) {
            ll temp = 0;
            temp += a[i];
            mx = max(temp,mx);
        }
        cout<<mx<<"\n";
    }
	return 0;
}


//                _
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/
//                  |___/                         |_|
//code by smigwump
//https://codeforces.com/blog/entry/62393 hashing hack protection
//https://codeforces.com/blog/entry/61587 rand() alternatives
//https://codeforces.com/blog/entry/61675 randomized hack protection
//https://en.wikipedia.org/wiki/Fermat's_little_theorem
//https://en.wikipedia.org/wiki/Euler%27s_totient_function
#include <bits/stdc++.h>
typedef long long ll;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)

using namespace std;

int main() {
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	// #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin>>tc;
    while(tc--) {
    	ll n = 1;
        cin>>n;
        vector<ll> a(n,0);
        REP(i,0,n-1) {
            cin>>a[n-1-i];
        }
        // for(auto it : a) {
        //     cout<<it<<" ";
        // }
        // cout<<"\n";
        PER(i,n-1,1) {
            if(a[i]>0) {
                ll j = i-1;
                while(j>=0) {
                    if(a[j] < 0) {
                        if(abs(a[j])>a[i]) {
                            a[j] += a[i];
                            a[i] = 0;
                        }
                        else {
                            ll temp1 = a[j], temp2 = a[i];
                            a[i] += temp1;
                            a[j] = 0;
                        }
                        break;
                    }
                    else {
                        j--;
                    }
                }
            }
        }
        vector<ll> a1 = a;
        while(1) {
            PER(i,n-1,1) {
                if(a[i]>0) {
                    ll j = i-1;
                    while(j>=0) {
                        if(a[j] < 0) {
                            if(abs(a[j])>a[i]) {
                                a[j] += a[i];
                                a[i] = 0;
                            }
                            else {
                                ll temp1 = a[j], temp2 = a[i];
                                a[i] += temp1;
                                a[j] = 0;
                            }
                            break;
                        }
                        else {
                            j--;
                        }
                    }
                }
            }
            vector<ll> tans = a;
            if(tans==a1) {
                break;
            }
            else {
                a1 = tans;
            }
        }
        // for(auto it : a) {
        //     cout<<it<<" ";
        // }
        // cout<<"\n";
        ll ans = 0;
        REP(i,0,n-1) {
            if(a[i]>0) {
                ans+=a[i];
            }
        }
        cout<<ans<<"\n";
        // cout<<"\n";
    }
	return 0;
}


//                _
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/
//                  |___/                         |_|
//code by smigwump
//https://codeforces.com/blog/entry/62393 hashing hack protection
//https://codeforces.com/blog/entry/61587 rand() alternatives
//https://codeforces.com/blog/entry/61675 randomized hack protection
//https://en.wikipedia.org/wiki/Fermat's_little_theorem
//https://en.wikipedia.org/wiki/Euler%27s_totient_function
#include <bits/stdc++.h>
typedef long long ll;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)

using namespace std;

int main() {
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	// #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin>>tc;
    while(tc--) {
    	ll n;
        cin>>n;
        vector<ll> a(n,0);
        REP(i,0,n-1) {
            cin>>a[i];
        }
        //answer is the max suffix sum ..... THINK!!!!!!!!!
        ll mx = -1;
        REP(i,0,n-1) {
            ll temp = 0;
            REP(j,i,n-1) {
                temp += a[j];
            }
            mx = max(temp,mx);
        }
        cout<<mx<<"\n";
    }
	return 0;
}


//                _
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/
//                  |___/                         |_|
//code by smigwump
//https://codeforces.com/blog/entry/62393 hashing hack protection
//https://codeforces.com/blog/entry/61587 rand() alternatives
//https://codeforces.com/blog/entry/61675 randomized hack protection
//https://en.wikipedia.org/wiki/Fermat's_little_theorem
//https://en.wikipedia.org/wiki/Euler%27s_totient_function
#include <bits/stdc++.h>
typedef long long ll;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)

using namespace std;

int main() {
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	// #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin>>tc;
    while(tc--) {
    	ll n;
        cin>>n;
        vector<ll> a(n,0);
        REP(i,0,n-1) {
            cin>>a[i];
        }
        reverse(all(a));
        // for(auto it : a) {
        //     cout<<it<<" ";
        // }
        // cout<<"\n";
        PER(i,n-1,1) {
            if(a[i]>0) {
                ll j = i-1;
                while(j>=0) {
                    if(a[j] < 0) {
                        if(abs(a[j])>a[i]) {
                            a[j] += a[i];
                            a[i] = 0;
                        }
                        else {
                            ll temp1 = a[j], temp2 = a[i];
                            a[i] += temp1;
                            a[j] = 0;
                        }
                        break;
                    }
                    else {
                        j--;
                    }
                }
            }
        }
        PER(i,n-1,1) {
            if(a[i]>0) {
                ll j = i-1;
                while(j>=0) {
                    if(a[j] < 0) {
                        if(abs(a[j])>a[i]) {
                            a[j] += a[i];
                            a[i] = 0;
                        }
                        else {
                            ll temp1 = a[j], temp2 = a[i];
                            a[i] += temp1;
                            a[j] = 0;
                        }
                        break;
                    }
                    else {
                        j--;
                    }
                }
            }
        }
        // for(auto it : a) {
        //     cout<<it<<" ";
        // }
        // cout<<"\n";
        ll ans = 0;
        REP(i,0,n-1) {
            if(a[i]>0) {
                ans+=a[i];
            }
        }
        cout<<ans<<"\n";
        // cout<<"\n";
    }
	return 0;
}


//                _
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/
//                  |___/                         |_|
//code by smigwump
//https://codeforces.com/blog/entry/62393 hashing hack protection
//https://codeforces.com/blog/entry/61587 rand() alternatives
//https://codeforces.com/blog/entry/61675 randomized hack protection
//https://en.wikipedia.org/wiki/Fermat's_little_theorem
//https://en.wikipedia.org/wiki/Euler%27s_totient_function
#include <bits/stdc++.h>
typedef long long ll;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)

using namespace std;

int main() {
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	// #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin>>tc;
    while(tc--) {
    	ll n;
        cin>>n;
        vector<ll> a(n,0);
        REP(i,0,n-1) {
            cin>>a[n-1-i];
        }
        // for(auto it : a) {
        //     cout<<it<<" ";
        // }
        // cout<<"\n";
        PER(i,n-1,1) {
            if(a[i]>0) {
                ll j = i-1;
                while(j>=0) {
                    if(a[j] < 0) {
                        if(abs(a[j])>a[i]) {
                            a[j] += a[i];
                            a[i] = 0;
                        }
                        else {
                            ll temp1 = a[j], temp2 = a[i];
                            a[i] += temp1;
                            a[j] = 0;
                        }
                        break;
                    }
                    else {
                        j--;
                    }
                }
            }
        }
        vector<ll> a1 = a;
        while(1) {
            PER(i,n-1,1) {
                if(a[i]>0) {
                    ll j = i-1;
                    while(j>=0) {
                        if(a[j] < 0) {
                            if(abs(a[j])>a[i]) {
                                a[j] += a[i];
                                a[i] = 0;
                            }
                            else {
                                ll temp1 = a[j], temp2 = a[i];
                                a[i] += temp1;
                                a[j] = 0;
                            }
                            break;
                        }
                        else {
                            j--;
                        }
                    }
                }
            }
            vector<ll> tans = a;
            if(tans==a1) {
                break;
            }
            else {
                a1 = tans;
            }
        }
        // for(auto it : a) {
        //     cout<<it<<" ";
        // }
        // cout<<"\n";
        ll ans = 0;
        REP(i,0,n-1) {
            if(a[i]>0) {
                ans+=a[i];
            }
        }
        cout<<ans<<"\n";
        // cout<<"\n";
    }
	return 0;
}


//                _
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/
//                  |___/                         |_|
//code by smigwump
//https://codeforces.com/blog/entry/62393 hashing hack protection
//https://codeforces.com/blog/entry/61587 rand() alternatives
//https://codeforces.com/blog/entry/61675 randomized hack protection
//https://en.wikipedia.org/wiki/Fermat's_little_theorem
//https://en.wikipedia.org/wiki/Euler%27s_totient_function
#include <bits/stdc++.h>
typedef long long ll;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)

using namespace std;

int main() {
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	// #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin>>tc;
    while(tc--) {
    	ll n;
        cin>>n;
        vector<ll> a(n,0);
        REP(i,0,n-1) {
            cin>>a[i];
        }
        //answer is the max suffix sum ..... THINK!!!!!!!!!
        ll mx = 0;
        REP(i,0,n-1) {
            mx = max(0LL,(mx+a[i]));
        }
        cout<<mx<<"\n";
    }
	return 0;
}


//                _
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/
//                  |___/                         |_|
//code by smigwump
//https://codeforces.com/blog/entry/62393 hashing hack protection
//https://codeforces.com/blog/entry/61587 rand() alternatives
//https://codeforces.com/blog/entry/61675 randomized hack protection
//https://en.wikipedia.org/wiki/Fermat's_little_theorem
//https://en.wikipedia.org/wiki/Euler%27s_totient_function
#include <bits/stdc++.h>
typedef long long ll;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)

using namespace std;

int main() {
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	// #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin>>tc;
    while(tc--) {
    	ll n;
        cin>>n;
        vector<ll> a(n,0);
        REP(i,0,n-1) {
            cin>>a[i];
        }
        //answer is the max suffix sum ..... THINK!!!!!!!!!
        ll mx = 0;
        REP(i,0,n-1) {
            temp = 0;
            temp += a[i];
            mx = max(temp,mx);
        }
        cout<<mx<<"\n";
    }
	return 0;
}


//                _
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/
//                  |___/                         |_|
//code by smigwump
//https://codeforces.com/blog/entry/62393 hashing hack protection
//https://codeforces.com/blog/entry/61587 rand() alternatives
//https://codeforces.com/blog/entry/61675 randomized hack protection
//https://en.wikipedia.org/wiki/Fermat's_little_theorem
//https://en.wikipedia.org/wiki/Euler%27s_totient_function
#include <bits/stdc++.h>
typedef long long ll;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)

using namespace std;

int main() {
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	// #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin>>tc;
    while(tc--) {
    	ll n;
        cin>>n;
        vector<ll> a(n,0);
        REP(i,0,n-1) {
            cin>>a[i];
        }
        reverse(all(a));
        // for(auto it : a) {
        //     cout<<it<<" ";
        // }
        // cout<<"\n";
        PER(i,n-1,1) {
            if(a[i]>0) {
                ll j = i-1;
                while(j>=0) {
                    if(a[j] < 0) {
                        if(abs(a[j])>a[i]) {
                            a[j] += a[i];
                            a[i] = 0;
                        }
                        else {
                            ll temp1 = a[j], temp2 = a[i];
                            a[i] += temp1;
                            a[j] = 0;
                        }
                        break;
                    }
                    else {
                        j--;
                    }
                }
            }
        }
        vector<ll> a1 = a;
        while(1) {
            PER(i,n-1,1) {
                if(a[i]>0) {
                    ll j = i-1;
                    while(j>=0) {
                        if(a[j] < 0) {
                            if(abs(a[j])>a[i]) {
                                a[j] += a[i];
                                a[i] = 0;
                            }
                            else {
                                ll temp1 = a[j], temp2 = a[i];
                                a[i] += temp1;
                                a[j] = 0;
                            }
                            break;
                        }
                        else {
                            j--;
                        }
                    }
                }
            }
            vector<ll> tans = a;
            if(tans==a1) {
                break;
            }
            else {
                a1 = tans;
            }
        }
        // for(auto it : a) {
        //     cout<<it<<" ";
        // }
        // cout<<"\n";
        ll ans = 0;
        REP(i,0,n-1) {
            if(a[i]>0) {
                ans+=a[i];
            }
        }
        cout<<ans<<"\n";
        // cout<<"\n";
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long t, n, a[100005], c=0;
int main(){
    cin >> t;
    while(t--){
        c = 0;
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        for(int i = 0; i < n; i++){
            if(a[i] > 0){
                for(int k = i+1; k < n; k++){
                    if(a[k] < 0 && abs(a[k]) < a[i]){
                        a[i] += a[k];
                        a[k] = 0;
                    }
                    else if(a[k] < 0){
                        a[k] += a[i];
                        a[i] = 0;
                        break;
                    }
                }
            }
        }
        for(int i = 0; i < n; i++){
            //cout << a[i] << endl;
            if(a[i] > 0) c += a[i];
        }
    cout << c << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
long long t, n, a[100005], c=0, h=0;
int main(){
    cin >> t;
    while(t--){
        c = 0;
        h = 0;
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        for(int i = 0; i < n; i++){
            if(a[i] > 0){
                c += a[i];
            }
            else if(a[i] < 0 && c > abs(a[i])){
                c -= a[i];
                a[i] = 0;
            }
            else if(a[i] < 0){
                a[i] += c;
                c = 0;
            }
        }
        for(int i = 0; i < n; i++){
            if(a[i] < 0){
                h += abs(a[i]);
            }
        }
    cout << h << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
long long t, n, a[100005], c=0;
int main(){
    cin >> t;
    while(t--){
        c = 0;
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        for(int i = 0; i < n; i++){
            if(a[i] > 0){
                for(int k = i+1; k < n; k++){
                    if(a[k] < 0 && abs(a[k]) < a[i]){
                        a[i] += a[k];
                        a[k] = 0;
                    }
                    else if(a[k] < 0){
                        a[i] = 0;
                        a[k] += a[i];
                        break;
                    }
                }
            }
        }
        for(int i = 0; i < n; i++){
            cout << a[i] << endl;
            if(a[i] > 0) c += a[i];
        }
    cout << c << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
long long t, n, a[100005], c=0;
int main(){
    cin >> t;
    while(t--){
        c = 0;
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        for(int i = 0; i < n; i++){
            if(a[i] > 0){
                for(int k = i+1; k < n; k++){
                    if(a[k] < 0 && abs(a[k]) < a[i]){
                        a[i] += a[k];
                        a[k] = 0;
                    }
                    else if(a[k] < 0){
                        a[i] = 0;
                        a[k] += a[i];
                        break;
                    }
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(a[i] > 0) c += a[i];
        }
    cout << c << endl;
    }
}


#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

ll solve() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for(int i=0; i<n; i++)
    cin >> arr[i];

  for(int i=0; i<n; i++){
    if(arr[i] > 0){
      int j = i+1;
      while(arr[i] >0 && j<n){
        if(arr[j] < 0){
          int t = min(arr[i], abs(arr[j]));
          arr[i] -= t;
          arr[j] += t;
        }
        j++;
      }
    }
  }
  ll count = 0;
  for(int i=0; i<n; i++){
    if(arr[i] > 0) count += arr[i];
  }
  return count;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cout << solve() << '\n';
  }
  return 0;
}