


The first line of input contains an integer ‘T’ representing the number of test cases.
The first line of each test case contains one integer ‘N’ denoting the number.
For each test case, print output one integer ‘X’, where ‘X’ is the largest integer you can get.
Print the output of each test case 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^9
Time limit: 1 sec
The intuition here is that if there is a larger digit that is present later then swap these digits. It is optimal to swap the first such digit with the larger digit present after this digit position. The idea is to try to swap each digit with every other digit and then take the maximum number out of all numbers formed after swapping digits.
The algorithm is as follows :
The intuition here is that if there is a larger digit that is present later then swap these digits. It is optimal to swap the first such digit with the larger digit present after this digit position. We can do some pre-computation, to get the largest digit present after any other digit. For every digit ‘D’ in ‘N’, ‘LASTOCCURRENCEOFDIGIT[D]’ = position where it is present at last.
The algorithm is as follows :