1T = int(input())
2arr1 = []
3for i in range(0, T):
4 N = int(input())
5 arr = list(map(int,input().split()))
6 arr.sort()
7 count = arr[0]
8 for i in range(1, len(arr)):
9 count = count + arr[i]
10 arr1.append(count)
11print(sum(arr1))