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

l_coder: 2016-03-20 11:53:27

it says wrong answer even though it runs perfectly locally and on ideone and aviben yes i checked for input 1010 the output was 1111,i can't figure out the problem

mhto: 2016-03-17 18:42:18

[17/03/16] works locally and on ideone.. but WA here..
[25/02/17] finally solved .. learnt so much..

Last edit: 2017-02-28 20:27:12
codehacker999: 2016-03-17 17:39:37

cleared from todolist after a long time. :D

o_1234: 2016-03-14 18:52:26

aviben its 1111 for 1010

sinhaanimesh9: 2016-03-12 22:12:56

getting runtime error NZEC ..please help

vick_jamwal: 2016-03-12 18:37:58

Firstly i write code in Java but got TLE and then i tried in C++ and got accepted in 0.08 sec .

Last edit: 2016-03-12 18:38:28

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