#include<iostream>
using namespace std;
//快速排序
void quick_sort(int*& a, int start, int end) {
if (start > end) {
return;
}
int lflag = start;
int rflag = end;
int temp;
while (lflag != rflag){
while(a[lflag] < a[start] && lflag < rflag) {
lflag++;
}
while(a[rflag] >= a[start] && lflag < rflag) {
rflag--;
}
if (lflag < rflag) {
temp = a[lflag];
a[lflag] = a[rflag];
a[rflag] = temp;
}
}
temp = a[start];
a[start] = a[lflag];
a[lflag] = temp;
quick_sort(a, start, lflag-1);
quick_sort(a, lflag + 1, end);
return;
}
int main() {
int n;
cin >> n;
int* results = new int[n];
for (int i = 0; i < n; i++) {
int num;
cin >> num;
int* a = new int[num];
for (int k = 0; k < num; k++) {
cin >> a[k];
}
//快速排序
quick_sort(a, 0, num - 1);
results[i] = 0;
//最小两个数相加候后再排序
for (int k = 0; k < num - 1; k++) {
a[k + 1] = a[k] + a[k + 1];
results[i] += a[k + 1];
quick_sort(a, k + 1, num - 1);
}
delete[] a;
}
for (int i = 0; i < n; i++) {
cout << results[i] << endl;
}
delete[] results;
return 0;
}
08-13