
An integer has a monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x <= y.
Given ‘N’ = 987
The answer is 899 because that is the greatest monotone increasing number possible that is less than ‘N’.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first and the only line of each test case contains a single integer ‘N’.
For each test case, print a single line containing a single integer denoting the maximum monotone number less than or equal to the given number.
The output of each test case will be 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 ^ 9
Where ‘T’ is the total number of test cases, and 'N’ is the number given to us.
Time limit: 1 sec.
The main idea is to try all possible combinations of numbers that are less than or equal to the given number ‘N’ and pick the greatest possible number.
The main idea is to find the first point where the ‘i’th digit is greater than the ‘i+1’th digit and reduce the ‘i’th digit by 1 and all the rest should be set to 9.