Ishaan is given N integers in the form of an array A. He is asked to select all of these integers in any order. For selecting every integer he gets some points. He needs to maximize those points.

For every integer he selects, he gets points equal to the value of :

**the selected integer * number of integers selected before the current integer** (Refer example for explanation)

Help him find the maximum points he can get provided **he can select every integer exactly 1 time**.

**Input : **

First line of input contains a single integer T denoting the number of test cases.The first line of each test case contains an integer N.The second line contains N space-separated integers denoting the array A.

**Output : **

For each test case, print the required answer in a new line.

**Constraints : **

1 <= T <= 100

1 <= N <= 1000

1 <= A[i] <= 1000

**Example :
Input : **

3

5

1 2 2 4 9

3

2 4 6

4

2 2 2 2

54

16

12

**Explanation :
Case 1 : **

First he selects 1

Points : 1 * 0 (no integer selected before this)

Total Points = 0

Then he selects 2

Points : 2 * 1 (1 selected before this)

Total Points = 2

Then he selects 2

Points : 2 * 2 (1,2 selected before this)

Total Points = 6

Then he selects 4

Points : 4 * 3 (1,2,2 selected before this)

Total Points = 18

Then he selects 9

Points : 9 * 4 (1,2,2,4 selected before this)

Total Points = **54**

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

KshatriyaYash | 658 |

RuntimeTerror | 446 |

nikhil_sojan | 388 |

cypherr | 384 |

striver119 | 378 |

KshatriyaYash | 1066 |

nikhil_sojan | 972 |

lonecoder | 909 |

mazumderrohit8 | 864 |

SumitSingh27 | 832 |

blackshadows | 5327 |

Ibrahim Nash | 5215 |

akhayrutdinov | 5111 |

mb1973 | 4462 |

Quandray | 4444 |

Login to report an issue on this page.