시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB189646040.268%

문제

A number is said to Rise and Fall if the decimal representation can be broken up into two parts (possibly empty) where the first part has digits in nondecreasing order and the second part has digits in nonincreasing order.

Compute the largest number less than or equal to an input number that rises and falls.

입력

The first line of input contains an integer $t$ ($1 \le t \le 10^5$), which is the number of test cases.

Each of the next $t$ lines contains a single integer $n$ ($1 \le n < 10^{100{,}000}$). Each is a single test case.

  • Note: that is not a typo. The integer can be up to $10^5$ digits long.

The sum of the lengths of all input test cases will not exceed $10^5$.

출력

For each test case, output a single line with a single integer, which is the largest number less than or equal to the $n$ for that test case that rises and falls.

예제 입력 1

2
29041
56577

예제 출력 1

29000
56555