// Arup Guha
// 11/15/2013
// Solution to COP 3502 Recitation Program 7: Stones

#include <stdio.h>

void quicksort(int* numbers, int low, int high);
int partition(int* vals, int low, int high);
void swap(int *a, int *b);

int main() {

    int n, i, loop;
    scanf("%d", &n);

    // Go through each case.
    for (loop=0; loop<n; loop++) {

        // Read in the array.
        int size;
        scanf("%d", &size);
        int* vals = malloc(size*sizeof(int));
        for (i=0; i<size; i++)
            scanf("%d", &vals[i]);

        // Sort it.
        quicksort(vals, 0, size-1);

        // Calculate the sum of moving each pile and print.
        long long sum = 0;
        for (i=0; i<size; i++)
            sum += ( ((long long)(size-1-i))*vals[i]);
        printf("%lld\n", sum);

        free(vals);
    }

    return 0;
}

/*** Quick Sort code from class website below ***/

// Pre-condition: s and f are value indexes into numbers.
// Post-condition: The values in numbers will be sorted in between indexes s
//                 and f.
void quicksort(int* numbers, int low, int high) {

    // Only have to sort if we are sorting more than one number
    if (low < high) {
        int split = partition(numbers,low,high);
        quicksort(numbers,low,split-1);
        quicksort(numbers,split+1,high);
    }
}

// Pre-condition: low and high are valid indexes into values
// Post-condition: Returns the partition index such that all the values
//                 stored in vals from index low to until that index are
//                 less or equal to the value stored there and all the values
//                 after that index until index high are greater than that
//                 value.
int partition(int* vals, int low, int high) {

    int temp;
    int i, lowpos;

    // A base case that should never really occur.
    //if (low == high) return low;

    // Pick a random partition element and swap it into index low.
    i = low + rand()%(high-low+1);
    swap(&vals[low], &vals[i]);

	// Store the index of the partition element.
	lowpos = low;

	// Update our low pointer.
	low++;

	// Run the partition so long as the low and high counters don't cross.
	while (low <= high) {

		// Move the low pointer until we find a value too large for this side.
		while (low <= high && vals[low] <= vals[lowpos]) low++;

		// Move the high pointer until we find a value too small for this side.
		while (high >= low && vals[high] > vals[lowpos]) high--;

		// Now that we've identified two values on the wrong side, swap them.
		if (low < high)
		   swap(&vals[low], &vals[high]);
	}

	// Swap the partition element into it's correct location.
	swap(&vals[lowpos], &vals[high]);

	return high; // Return the index of the partition element.
}

// Swaps the values pointed to by a and b.
void swap(int *a, int *b) {
     int temp = *a;
     *a = *b;
     *b = temp;
}
