


The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first line of each test case contains the number of ropes.
The second line of each test case contains space-separated integers containing the length of ropes.
For each test case, print the minimum cost to connect all the ropes. Each value is separated by a single space.
The output of each test case is printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^4
1 <= length[i] <= 10^4
Where 'length[i]' is the length of the 'i-th' rope.
Time Limit: 1 sec
When closely observed, it can be seen that the ropes which are connected first add up to the total cost more number of times than the ones which are connected later. So, to reduce this cost, that is being added again and again, shorter ropes are connected first moving on to longer ones.
The idea is the same as the previous approach but to find the two smallest values from the length array, for that, we use two variables. Then replace one of those values with the sum of them and another with INF. Maintain a variable 'MIN_COST' and keep on adding the cost of connecting ropes in 'MIN_COST'. Repeat the same process until all the ropes are connected.
The idea is the same as discussed in the previous approach, but can the same idea be implemented in a better way. Think of a data structure that can give us the minimum value in a time that is less than sorting it again and again. Min-Heap is one such data structure whose root gives the minimum value in constant time. In addition to any new element in the heap, heapify function takes place and takes logarithmic time.