1 #include <cstdio>
2 #include <iostream>
3 #include <cmath>
4 #include <cstring>
5 using namespace std;
6 int n,datanum,maxn;
7 int a[50000+10],leftmax[50000+10],rightmax[50000+10];
8 int main()
9 {
10 int w,i;
11 scanf("%d",&datanum);
12 for (w=1;w<=datanum;w++)
13 {
14 memset(a,0,sizeof(0));
15 memset(leftmax,0,sizeof(leftmax));
16 memset(rightmax,0,sizeof(rightmax));
17 scanf("%d",&n);
18 for (i=1;i<=n;i++)
19 scanf("%d",&a[i]);
20 leftmax[1]=a[1];
21 for (i=2;i<=n;i++)
22 if (leftmax[i-1]>0) leftmax[i]=leftmax[i-1]+a[i];
23 else leftmax[i]=a[i];
24 for (i=2;i<=n;i++)
25 if (leftmax[i]<leftmax[i-1]) leftmax[i]=leftmax[i-1];
26 rightmax[n]=a[n];
27 for (i=n-1;i>=1;i--)
28 if (rightmax[i+1]>0) rightmax[i]=rightmax[i+1]+a[i];
29 else rightmax[i]=a[i];
30 for (i=n-1;i>=1;i--)
31 if (rightmax[i]<rightmax[i+1])
32 rightmax[i]=rightmax[i+1];
33 maxn=-99999999;
34 for (i=1;i<n;i++)
35 maxn=max(maxn,leftmax[i]+rightmax[i+1]);
36 printf("%d
",maxn);
37 }
38 return 0;
39 }