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
ashish: 2015-04-20 20:49:43

Hello admin/problem setter, can you please check why I am a getting wrong answer? Id: 14128402

Also can you please give at-least 1 testcase where I am getting a wrong answer?

Anakar Parida: 2015-04-19 16:32:41

I am also fed up with wrong solution. Handled all cases from 1 to 999999999999999999. Dont know what else is needed

Eknoor Jassal: 2015-04-19 15:49:39

I would restate what everyone is saying. I not " all about nines". Its about "all nines" ;)

Anakar Parida: 2015-04-18 19:46:17

One small suggestion for all people who are facing "wrong answer".. Single digit number is not palindrome. Do make sure your code handles it.

shomit: 2015-04-17 21:57:10

i have tried this code for every case yet it says wrong answer.Please list the difference test cases.....ughh i am fed up with this one

saki: 2015-04-16 18:36:46

Guys i am new to SPOJ, not sure where to post my source code so that someone can check why it is showing wrong answer, I got exact o/p as mentioned in the question when done in Putty. Please help!

akshay93: 2015-04-14 12:30:51

it works fine on code blocks but on the site its shows wrong answer. Guys please help.

Vijay: 2015-04-14 10:55:38

Not as easy and mathematical as it looks .
As written by others in comments "its all about nine"

PRAFUL ANAND: 2015-04-11 15:37:36

after submission of code if status shows wrong answer. please please...... show me for which test case my code is showing wrong answer and what is the expected output and your output for that particular test case. It will be helpful to debugg the program.

Last edit: 2015-04-11 15:41:58
Punit Bhatt: 2015-04-11 00:23:28

My submission is not getting accepted but "runtime error (SIGSEGV)" is being displayed. Can someone please explain what this means ?? When i tested the program, the outputs were right. But still this error is being displayed.


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