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


hide comments
coolbudy1998: 2017-11-24 16:46:21

Please provide a sample of a number with 53435 digits...i think my whole computer screen will fill away. Is the language given in prob statement is wrong?? 1000000 digits should be replaced with only 1000000. Isn't it?

dsr: 2017-11-19 21:30:23

Why am I getting NZEC for python :'(

prothlete: 2017-11-18 17:52:17

in my ide, i get the correct answer against every possible test case, but here, why does it show wrong answer?

w1583236: 2017-11-08 20:51:02

My code exceeded the time limit. Does that imply there would be any redundancy in my code ?

gauravsood_: 2017-10-31 14:57:27

use string not integer, refer to geeks for geeks article for next palindrome, don't forget to include case 0000000 and 000000xxxx where xxx can be any number. goodluck :)

manjeet_: 2017-10-30 14:22:55

there are no cases like 001 .. so dont worry.. i've submitted without even checking them

gaurav__404: 2017-10-26 17:18:03

a small mistake can waste your 3 hours ;-| every thing is mentioned in this question and end line is important

neildcruze: 2017-10-26 07:29:50

Why is it showing compilation error? When I run the same code on my computer, it works perfectly.

marcognox: 2017-10-19 15:41:48

Theoden's test cases are recommended, plus "23726 -> 23732" (this case took me a lot of time to figure out)

vivace_jr: 2017-10-07 15:24:44

000 gives 010 as output...huh..this is bad


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

Problem's scores 1 vote

Concept difficulty
Concept difficulty 37%
Implementation difficulty
Implementation difficulty 50%
468 16