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-08-28 21:45:58 sitaram
running in codeblock...........but showing wrong answer here
2014-08-27 16:41:55 Nandan Mankad
Really Nice One! Finally AC after a good amount of struggle!
2014-08-26 15:39:54 Utkarsh
What should be the output in case of single digit integers?

Leppy: Why should one digit be handled differently than 3 or 5 or 1000000 digits?

Last edit: 2014-08-27 18:21:09
2014-08-24 15:13:05 Nazib Sorathiya
Time Limit Exceeded !!!!!!!
Common in my system there is no time lag for output and also on Ideone.com(online terminal for gcc)time shown is 0,then how come time limit is exceeding
2014-08-22 20:39:44 GURUPREET SINGH
do we need to consider 0 as an input??

(reply by cyclops) Positive means greater than zero.

Last edit: 2014-08-22 23:00:56
2014-07-30 00:50:18 Hidenori
It's very easy to write bruteforce solution, so it was really easy to test!
2014-07-27 17:31:11 LeppyR64
Read the problem statement carefully there have been many posts on the forum with people missing the same detail:
"For a given positive integer K of not more than 1000000 digits"
2014-07-26 20:52:06 Nakul Mohan
nice problem...AC finally :)
2014-07-21 16:28:30 Zishan Ahmad
what is the upper limit of t ?
2014-07-13 06:38:05 Yevgen Yampolskiy
WARNING: last line does not have terminating '\n'. If you implement your own I/O library then you may run into an issue (as I did)

Last edit: 2014-07-13 17:43:42
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.