// Arup Guha
// 2/23/2016
// Solution to 2016 FHSPS Playoff Problem: Sorting Exams

import java.util.*;

public class sorting {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Go through each case.
		for (int loop=0; loop<numCases; loop++) {

			int n = stdin.nextInt();
			PriorityQueue<Integer> q = new PriorityQueue<Integer>();

			// Put everything in the queue.
			for (int i=0; i<n; i++)
				q.offer(stdin.nextInt());

			// With the input bounds an int will suffice
			int cost = 0;

			// Just do a greedy; take the two smallest remaining...
			while (q.size() > 1) {

				// Take out the two smallest.
				int a = q.poll();
				int b = q.poll();

				// Update our cost.
				cost += (a+b);

				// Put back the combined value...
				q.offer(a+b);
			}

			// This is our answer...
			System.out.println(cost);
		}
	}
}
