


If two numbers have the same frequency then keep the one that was present before the other in the original given list (array) first.
Input: arr[] = {2, 5, 2, 8, 5, 6, 8, 8}
Output: arr[] = {8, 8, 8, 2, 2, 5, 5, 6}
Explanation :
When you sort the array based on the decreasing order of the frequency of repetition of integers in the original array,
you’ll find that the element ‘8’ is the integer with the most repeated values therefore it would be arranged first after which since both 2 and 5 have the same number of repeated
values in the original array but since the 2 arrived first so we will first arrange 2 and then 5 in our resultant array, while would be the last element after sorting here.
The first line of input contains a single integer ‘T’ denoting the number of test cases that would be there.
The first line of each test case contains a single integer ‘N’ denoting the number of integers that would be given.
And the next line contains ‘N’ space-separated integers which are the elements of the list.
For each test case, print the sorted list of elements by the decreasing order of their frequency of repetition in the list.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 3000
1 <= NUMS[i] <= 10^6
Where 'NUMS[i]' denotes the 'ith' element of the given array.
Time Limit: 1sec
The idea here is to keep a maintained list of the counts of the various elements given in the list and sort it in descending order based on their frequency counts and now keep the index values of the items and order them in ascending order.
The algorithm will be-