import java.io.*;
import java.util.*;

// Solves the add all problem from Arup's webiste using a priority queue and a greedy heuristic
public class addAll{
	
	// The main method
	public static void main(String[] Args){
		Scanner stdin = new Scanner(System.in);
		
		// Read in the number of test cases
		int numCases = stdin.nextInt();
		
		// Some magic manipulation of decrementing and checking
		while (numCases-->0) {
			
			// Read in the number of numbers
			int numnum = stdin.nextInt();
			
			// Initialize the priority queue
			PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
			
			// Read in the orignal numbers and add them to the priority queue
			for (int i = 0; i < numnum; i++){
				pq.add(stdin.nextInt());
			}
			
			// Store the answer as a long since the answer can get larger than 2^32
			long cost = 0;
			
			// Loop while ther are numbers to add togehter
			while (pq.size() > 1){
				
				// Add the least numbers togehter and update the priority queue
				int a = pq.poll();
				int b = pq.poll();
				cost += a+b;
				pq.add(a+b);
			}
			
			// Print the answer
			System.out.println(cost);
		}
	}
}