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
2014-01-15 15:17:31 Sachin Sai Krishna M
for 9 the ans should be 11 but if even 9 gets printed u can get AC:) pls check that one
2014-01-15 15:17:31 Gaurav Mishra
To much hard coding :(
2014-01-15 15:17:31 ISHANI
GREEN LINE after hard hard coding
but really VERY VERY NICE LOGIC
2014-01-15 15:17:31 Abhash Singh
3.5 hrs straight into this one!
AC in first attempt!
no points!what is this! :(
2014-01-15 15:17:31 Bernardo de Freitas Zamperetti
make sure that your program can accept numbers with at least 1000000 *DIGITS*

Last edit: 2013-05-03 15:22:37
2014-01-15 15:17:31 Guo Zhiming
The version of Clojure is tooooo old. can anybody update it to 1.3 or 1.5?
2014-01-15 15:17:31 Shrinidhi Sondur
This one was good. Real good. If you stick to it for some time you'll crack it.
2014-01-15 15:17:31 lukan thorare
http://ideone.com/******
plz help!

--ans--> Please use the forum, it is made for those questions.

Last edit: 2013-03-16 14:03:08
2014-01-15 15:17:31 Bumbler
Awesome problem !!
2014-01-15 15:17:31 Junior Prog
How to handle large numbers like 100000 digit numbers used here??

reply: string

Last edit: 2013-01-10 19:04:01
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.