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-06-24 18:55:56 Ishaan
Getting TLE when compiling the problem. Almost tested for test case my algorithm works fine. I am using python for the problem. How to minimize my time. Any suggestion will welcomed. (I am newbie in python - any helpful syntax??)
2015-06-23 19:18:44 kunal
How to store a 100000 digit no ??
2015-06-22 17:07:37
getting the correct answer of my code on my pc and also on ideone
2015-06-22 10:15:09 Amitayush Thakur
This problem requires you to take care of so many test cases. There is a possibility of error even when you check for tricky cases like 9,99,100,101 etc. Also do remember answer for single digit numbers will not be 11.
(edit)-> single digit numbers except 9.

Last edit: 2015-06-22 10:16:41
2015-06-21 21:19:40 MANISH KUMAR
pleaselet me know the answer

Last edit: 2015-06-21 21:21:02
2015-06-21 21:15:38 MANISH KUMAR
i have checked with 9,11,99,100,9999, and the output is 11,22,101,101,1001,but stillwa
2015-06-20 22:14:38 Shriram Rahatgaonkar
Surprised, got AC in first try, without even debugging anything. :O
2015-06-17 09:06:34 Abhishek
If the input number is greater than 1000000,then what am i supposed to do ?? should i terminate the program ??
2015-06-17 07:31:59
if you are getting too many WA ,try these test cases :9,11,99,100,9999 and check whether you are getting 11,22,101,101,10001 as answers......

Last edit: 2015-06-17 07:33:17
2015-06-16 16:49:31
works in codechef...doesnt work here...saying wrong answer...why?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.