1 #include<cstdio>
2 #include<queue>
3 using namespace std;
4
5 int main()
6 {
7 //freopen("in.txt","r",stdin);
8 bool flag;
9 int t,n;
10 scanf("%d",&t);
11 while(t--)
12 {
13 flag=false;
14 priority_queue<int,vector<int>,greater<int> >que;
15 long long int ans;
16 scanf("%d",&n);
17 if(n==1)flag=true;
18 while(n--)
19 {
20 int temp;
21 scanf("%d",&temp);
22 que.push(temp);
23 }
24 if(flag)
25 {
26 printf("0
");
27 continue;
28 }
29 ans=0;
30 while(1)
31 {
32 int temp1,temp2;
33 temp1=que.top();
34 que.pop();
35 temp2=que.top();
36 que.pop();
37 que.push(temp1+temp2);
38 ans+=(long long int)(temp1+temp2);
39 if(que.size()==1)
40 break;
41 }
42 printf("%lld
",ans);
43 }
44 return 0;
45 }