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


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

hide comments
2015-07-16 15:41:18
PALIN in my compiller it is executed u give so many large number it does care but here wrong answer coming.what the fuck is this
2015-07-11 20:47:42 Livewire
:D Got AC in 2nd attempt!
2015-07-11 01:58:55 Abhishek Prasad
14643636.. can anyone please suggest me what did I do wrong here?
2015-07-10 07:18:39 poojan
giving me wrong ans :
i take care of :
1->0 to 8-> digit+1
2->9,99,999,9999->11,101,1001.10001
3->405,504->414,505
4->998,989->999,999
5->421999767->422000224
6->100->101
still getting wrong ans plz help! lots of wrong ans for this and problem statment is very bad! not clear about single digit.
cheak my code id is : 14637932

Last edit: 2015-07-10 08:15:07
2015-07-08 18:26:15
check for the cases 421999767,429964
2015-07-08 02:38:16
I made brute force algorithm, compared it with my algorithm using 10000 random numbers 0..10000, got exactly the same results, but still WA for non brute force. Could someone give me some tricky examples for testing (I already tested most from comments)?
Also, should I assume that there is '\n' on the end of each input line?
2015-07-07 20:08:13
<snip> Can anyone tell me why am I getting a WA? Got it, thanks anyways.

Last edit: 2022-07-26 22:22:47
2015-07-06 19:57:42 Loong
<snip>
fxxk it!!! finally got AC (C in 0.16s), the algorithm is simple, here are some other tips for "always WA" guys:
1. answers for single digit below 9 can either be digit+1 or 11.
2. do not use EOF as the ending condition when looping on the whole input, instead, use '\n' or EOF for line seperator. otherwise you will miss the final test case and get WA.

Last edit: 2022-07-26 22:22:53
2015-07-02 07:53:08 Punit Bhatt
<snip>
I am getting wrong answer for my code . I have tested my code with many sample inputs and getting the required output. I have taken care of the case related to 9s. Can sumone please check my code and help me ? Thank You


Last edit: 2022-07-26 22:22:58
2015-07-01 18:31:46 deeksha
my code is showing coorect output still it is showing wrong answer
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.