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-01-13 17:38:40 Kaushik Nath
i am taking input through strings
and getting correct answer at ideone but not at spoj
please help
2015-01-12 19:48:47 Rajat
extremely good question. :)
2015-01-08 15:28:22 hanu_man
it is all about nines....
2015-01-08 10:13:59 praveen anuranjan
<snip> every answer is coming true and still giving WA someone plzzz help

Last edit: 2022-07-26 22:29:18
2015-01-07 14:58:52 Trailblazer
Does inputs are not separated by '\n' ?
If not then how it would be read.
2015-01-07 04:48:19 Novice Whistler
@Punit, you have taken the data type of inputs as long. This will not be able to hold a 10000 digit number. So, the test cases beyond the "capacity" of long will not pass.Try using string for this.

Last edit: 2015-01-07 04:49:22
2015-01-03 08:11:38 Ankit Srivastava
Please help point where I am hitting TLE - <snip>

Last edit: 2022-07-26 22:29:13
2015-01-02 11:33:13 Punit Bhatt
Tried solving this problem. Got right answers in all cases but am getting wrong answer here in spoj. Please help me out
ideone.com/iu5T4S
2014-12-29 06:38:12 Nazmul Hossain
I am getting runtime error NZEC ....
2014-12-27 05:17:21 Ankit
Its a general question. I am not sure of the answer.
How should the input ouput sequence be for problems.?

Input
Input
Input
Input

Output
Output
Output
Output

" OR "
Input
Output
Input
Output
Input
Output

Last edit: 2014-12-27 05:17:46
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.