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
2021-08-19 08:18:34
Testcases given by Shreyas all are passed but not accepted
2021-08-19 08:12:14
what is wrong in <snip> ?

[NG]: Read the footer.

Last edit: 2021-08-19 10:30:43
2021-08-11 11:36:17
can anyone explain the concept
2021-06-23 15:31:46
FUCK YES
2021-06-02 16:17:08
One of the best problems ever faced.
2021-06-02 12:54:39
lessgoo
2021-05-10 08:40:49
2 hrs got AC
2021-04-14 19:55:48
why the next palindrome of 0003 is 0110 and not 4 ?
2021-03-22 21:59:34
Started On 12 am
AC at 2.29 am
2021-03-20 08:39:44
AC with Java after 5-6 TLEs...
Use BufferedReader and BufferedWriter for fast I/O, use strings and char instead of int array. DON'T convert the input number to BigInteger as it will slow your program down.
Learnt quite a bit... Good luck!
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.