public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
int a[] = new int[n];
for(int j =0;j<n;j++)
{
a[j]=sc.nextInt();
}
findSumOFCircular(a);
}
}
public static void findSumOFCircular(int a[]) {
for(int i=0;i<a.length;i++)
{
a[i]=a[i]*(-1);
}
//now using the kadaens algo for finding the sum of highest
int i =0;
int max_so_far=a[i];
int max_ending_here =0;
int start=0,s=0,e=0;
for(i=0;i<a.length;i++)
{
max_ending_here=max_ending_here + a[i];
if(max_so_far<max_ending_here) {
max_so_far=max_ending_here;
start =s;e=i;
}
if(max_ending_here<0) {
max_ending_here=0;
s=i+1;
}
}
int sum =0;
for(int j=0;j<a.length;j++)
{
a[i]=a[i]*(-1);
}
for(int j =0;j<a.length;i++)
{
sum =sum+a[j];
}
System.out.println(sum-max_so_far);