https://codeforces.com/contest/1845/problem/D
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
//typedef __int128 LL;//2的128
typedef long long ll; //2的64
// 1e9,, 1e19,,1e38
int n,ans,st;
int a[300010];
int maxd;
int minx;
int inf=1e18;
void solve()
{cin>>n;
maxd=-inf; minx=inf;
ans=0;
for(int i=1;i<=n;i++)
cin>>st,a[i]=a[i-1]+st;
for(int i=n;i>=0;i--)
{
if(maxd<a[i]-minx)
{
maxd=a[i]-minx; ans=a[i];
}
minx=min(minx,a[i]);
}
cout<<ans<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t; cin>>t;
while(t--)
{
solve();
}
return 0;
}