#include <iostream>
#include <cstdio>
using namespace std;
long long dp[2][50010];
int num[50010];
const long long INF=((long long)1<<63);
int main()
{
// ios::sync_with_stdio(false);
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&num[i]);
int i;
long long sum,maxn;
for(sum=i=0,maxn=INF;i<n;i++) //从左记录最大值
{
sum+=num[i];
maxn=max(maxn,sum);
if(sum<0)
sum=0;
dp[0][i]=maxn;
}
for(sum=0,i=n-1,maxn=INF;i>=0;i--) //从右记录最大值
{
sum+=num[i];
maxn=max(maxn,sum);
if(sum<0)
sum=0;
dp[1][i]=maxn;
}
for(i=1,sum=INF;i<n;i++) //依次加和获得最终最大值
sum=max(sum,dp[0][i-1]+dp[1][i]);
printf("%lld\n",sum);
}
return 0;
}