TAMU Practice 2022-1a (RMRC 2017)

#### Start

2022-01-11 11:00 AKST

## TAMU Practice 2022-1a (RMRC 2017)

#### End

2022-01-11 14:00 AKST
The end is near!
Contest is over.
Not yet started.
Contest is starting in -133 days 1:20:16

3:00:00

0:00:00

# Problem EPalindromic Password

The IT department at your school decided to change their password policy. Each password will have to consist of $N$ $6$-digit numbers separated by dashes, where $N$ will be determined by the phase of the moon and the weather forecast for the day after it will be generated.

You realized that, if all of the numbers were palindromes (same numbers as the original ones if read backwards), you would have to remember a bunch of $3$-digit numbers, which did not sound that bad (at the time).

In order to generate your password of $N$ numbers, you get a list of $N$ randomly generated $6$-digit numbers and find the palindromic number closest to them.

Of course, you would like to automate this process...

## Input

The first line of the input contains a single positive integer $N \leq 1000$ indicating the number of six-digit numbers in the input. Each of the next $N$ lines contains a six-digit number without leading zeroes.

## Output

For each six-digit number in the input, output another six-digit number that is closest to it and is also a palindrome. “Closest” in this context means “a number having the smallest absolute difference with the original number”. If there are two different numbers satisfying the above condition, output the smaller one of the two. Remember, no leading zeroes.

Sample Input 1 Sample Output 1
2
123321
123322

123321
123321