Mingyun goes by the nickname debtor. The Kim Woohyun lab gave it to him because he is slow to pay back what he borrows.
Mingyun has borrowed money N times, and the ith loan is Ai. The lab collects its money in an unusual way.
When the lab orders Mingyun to settle M debts, he picks any M of the N loans. If the picked amounts are B1,B2,…,BM, he has to pay max(B1,B2,…,BM)×M. The part he pays beyond the amounts he actually borrowed is the extra payment, so the extra payment is max(B1,B2,…,BM)×M−(B1+B2+⋯+BM).
Suppose Mingyun borrowed 2, 5 and 3 in three loans and the lab orders him to settle two debts. If he picks the first and the second loan, he pays 5×2=10 and the extra payment is 10−(2+5)=3. If he picks the first and the third loan, he pays 3×2=6 and the extra payment is 6−(2+3)=1.
Mingyun wants the extra payment to be as small as possible. Let S(M) be the smallest extra payment he can reach when the lab orders him to settle M debts.
For N=5 with the loans 1,5,4,3,8 in that order:
Given N and A1,A2,…,AN, compute S(1)+S(2)+⋯+S(N).
The first line has the number of test cases T (1≤T≤10).
Each of the next T lines has the number of loans N (1≤N≤4000) followed by the borrowed amounts A1,A2,…,AN (1≤Ai≤10000), separated by spaces.
For each test case, print S(1)+S(2)+⋯+S(N) on its own line.
The answer and the intermediate values can exceed the 32-bit integer range, so use a 64-bit integer type.