# include<stdio.h>
# include<stdlib.h>
int cmp(const void *x,const void *y)
{
return *(int *)x-*(int *)y;
}
int main()
{
int N,i,j,k;
scanf("%d",&N);
while(N--)
{
int n;
long long sum =0;
scanf("%d",&n);
long long a[n],t;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
qsort(a,n,sizeof(a[0]),cmp);
for(;1;)
{
a[0]=a[0]+a[1];
sum = sum + a[0];
n=n-1;
if(n==1)
{
break;
}
for(j=1;j<n;j++)
{
printf("%d %d
",a[0],a[1]);
a[j]=a[j+1];
}
for(j=0;j<n-1;j++)
{
if(a[j]>a[j+1])/////错误!!!!!正解见下
{
t=a[j];a[j]=a[j+1];a[j+1]=t;
}
else
{
break;
}
}
}
printf("%d",sum);
}
return 0;
}
int k =a[j],l=a[j+1];
if(k>l)
{
t=a[j];a[j]=a[j+1];a[j+1]=t;
}