PALIN - The Next Palindrome

A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than 1000000 digits, write the value of the smallest palindrome larger than K to output. Numbers are always displayed without leading zeros.

Input

The first line contains integer t, the number of test cases. Integers K are given in the next t lines.

Output

For each K, output the smallest palindrome larger than K.

Example

Input:
2
808
2133

Output:
818
2222

Warning: large Input/Output data, be careful with certain languages


Added by:adrian
Date:2004-05-01
Time limit:2s-9s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6

hide comments
2018-02-28 20:06:24
Can someone tell me that what would be output if input > 1000000 .
2018-02-28 08:08:04
Same problem here..I get the correct answer on my code, still I get the wrong answer here, If only we could see what test case the code failed at, it would be great.
2018-02-18 07:28:23
can someone give some corner cases where code can go wrong


Last edit: 2018-02-18 08:11:07
2018-01-25 14:39:15
@quock The constraint is given on the number of digits
2018-01-25 10:20:38
I want to ask that if we have to find just preceding palindrome of the number then what should be the approach
2018-01-23 08:19:38
Here description say K can not be larger than 1000000 but the test cases assert also a big int
11111111111111111111211111111111111111111. Is it expecting case to cover ?
2018-01-15 19:39:46
can someone give me corner cases for this code that is easy to mistake?
2018-01-15 19:18:32
I got TLE in this program. How should i fix this?
2018-01-08 15:34:46
Nice problem ;)

If you analyse well enough you will find that there are many corner cases that will take care of themselves
2018-01-07 12:18:31
akash9827 Long int is too short to handle such long number as ~1000000 digits...
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.