Debt

No attempts yetTime limit1sMemory limit256 MB

Problem

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 NN times, and the iith loan is AiA_i. The lab collects its money in an unusual way.

When the lab orders Mingyun to settle MM debts, he picks any MM of the NN loans. If the picked amounts are B1,B2,,BMB_1, B_2, \dots, B_M, he has to pay max(B1,B2,,BM)×M\max(B_1, B_2, \dots, B_M) \times 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)\max(B_1, B_2, \dots, B_M) \times M - (B_1 + B_2 + \dots + B_M).

Suppose Mingyun borrowed 22, 55 and 33 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=105 \times 2 = 10 and the extra payment is 10(2+5)=310 - (2 + 5) = 3. If he picks the first and the third loan, he pays 3×2=63 \times 2 = 6 and the extra payment is 6(2+3)=16 - (2 + 3) = 1.

Mingyun wants the extra payment to be as small as possible. Let S(M)S(M) be the smallest extra payment he can reach when the lab orders him to settle MM debts.

For N=5N = 5 with the loans 1,5,4,3,81, 5, 4, 3, 8 in that order:

  • S(1)=0S(1) = 0. Any single loan works.
  • S(2)=1S(2) = 1. Pick 55 and 44, or pick 44 and 33.
  • S(3)=3S(3) = 3. Pick 5,4,35, 4, 3.
  • S(4)=7S(4) = 7. Pick 5,4,3,15, 4, 3, 1.
  • S(5)=19S(5) = 19. Pick all five.

Given NN and A1,A2,,ANA_1, A_2, \dots, A_N, compute S(1)+S(2)++S(N)S(1) + S(2) + \dots + S(N).

Input

The first line has the number of test cases TT (1T101 \le T \le 10).

Each of the next TT lines has the number of loans NN (1N40001 \le N \le 4000) followed by the borrowed amounts A1,A2,,ANA_1, A_2, \dots, A_N (1Ai100001 \le A_i \le 10000), separated by spaces.

Output

For each test case, print S(1)+S(2)++S(N)S(1) + S(2) + \dots + 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.