

So, when N loudspeakers are kept in order A1, A2, A3……….An, the combined loudness will be (A1^(A2^(A3^(...........(An))))). So, your task is to rearrange the loudspeakers such that the combined loudness emitted is maximum.
Let,
N = 3
LOUD = [4, 5, 6]
Answer:- [4, 5, 6]
Explanation:- The answer should be 4,5,6 because out of all the rearrangements that are possible the array [4,5,6] will emit the largest combined loudness. Arrangement 4,5,6 emits an amplitude of 4^5^6 (1152921504606846976) and arrangement 6,5,4 emits an amplitude of 6^5^4 (3656158440062976).
The first line contains a single integer ‘T’ representing the number of test cases. Then each test case follows.
The first line of each test case contains an integer ‘N’ denoting the number of loudspeakers you have.
The third line contains ‘N’ integers of the array ‘LOUD’ denoting the loudness of the speakers.
For each test case, print ‘N’ integers denoting the lexicographically smallest rearrangement of loudspeakers such that they emit the largest combined loudness.
The output of each test case should be printed in a separate line.
You are not required to print anything, it has already been taken care of. Just implement the function.
1 <= T <= 5
1 <= N <= 10^5
1 <= LOUD[i] <= 10^9
Note:- Loudspeakers having an amplitude of more than 1 will all have unique amplitudes.
Time Limit = 1 sec
We can observe that we have to keep the loudspeakers with amplitude at last as 1 raised to the power is 1 so we take out all the ones separately. Now, the key observation is x^y is always greater than y^x when x<y. The only exception to this is when x=2 and y=3. So, we treat the corner case [2,3] separately, else we print the array in ascending order.