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
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

fducck: 2017-10-05 14:15:12

Remember to check 0/000002133000/9/

Nguyễn Hoàng Nam: 2017-10-05 02:36:28

@prashant23: it just means you haven't checked deep enough. There can be really odd numbers which will cause really odd interaction. The example given by @theoden91 is a good one, try that.

prashant23: 2017-10-01 20:45:10

I am getting all the cases correct in my system but still getting the wrong answer, anyone has any idea.
Do test cases have leading zeros like 001

Last edit: 2017-10-01 20:47:36

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%
467 16