#include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<iostream> #include<algorithm> //friend bool operator < (Node a,Node b){ return a.coun>b.coun; } priority_queue<double> Q; using namespace std; struct node { int num; friend bool operator <(node a,node b) {return a.num>b.num;} }; int main() { int t,n; int i,j,k; scanf("%d",&t); while(t--) { node now,now1; priority_queue<node> q; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&now.num); q.push(now); } /*while(!q.empty()) { now=q.top(); q.pop(); printf("%d,.,. ",now.num); }*/ int ans=0; ans+=q.top().num; q.pop(); ans+=q.top().num; q.pop(); now.num=ans; q.push(now); //printf("%d... ",ans); while(!q.empty()) { now=q.top(); q.pop(); now1=q.top(); q.pop(); // printf("%d %d ",now.num,now1.num); ans+=(now.num+now1.num); now.num+=now1.num; if(!q.empty()) q.push(now); } printf("%d ",ans); } return 0; }