Rise and Fall

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

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 tt (1t1051 \le t \le 10^5), which is the number of test cases.

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

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

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

출력

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