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
subham92: 2016-04-27 14:06:43

time limit exceeded :( But it takes only 0.2 secs in ideone

starun8795: 2016-04-18 17:45:12

Hrithik, you can use a static array to handle big numbers in c/c++.

hrithik_sethia: 2016-04-18 07:42:54

how can we make any code to work for large input numbers ?? in cpp

q1_hoanglong: 2016-04-16 11:53:27

have everyone tried test inp 999 out 1001

manish3749: 2016-04-12 16:39:02

i have taken more than 100 test cases ..all of them paased but here it is showing wronf answer

ign_unnamed1: 2016-04-06 12:50:57

what does this error code mean "runtime error (NZEC)" . My code is working on "ideone" but not here. i have written my code in c#.
also what does this mean" positive integer K of not more than 1000000 digits" what is maxm value of K?

last_mohican: 2016-04-02 17:59:03

What happens if input integer is written with the beginning zero(s)? For example: 01010

ghostcoder123: 2016-04-02 14:30:19

please upgrade your fucking compilers in c atoi not working!

nischaymalhan: 2016-03-26 13:44:58

For those getting wrong answer it is probably because your code wont work for a large( e.g. : 100 )digit number

sonali9696: 2016-03-23 22:19:20

check for the following:
1900:1991,1991:2002,191:202


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

Problem's scores 1 vote

Concept difficulty
Concept difficulty 42%
Implementation difficulty
Implementation difficulty 48%
120 3