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
2016-04-16 11:53:27
have everyone tried test inp 999 out 1001
2016-04-12 16:39:02
i have taken more than 100 test cases ..all of them paased but here it is showing wronf answer
2016-04-06 12:50:57
what does this error code mean "runtime error (NZEC)" . My code is working on "ideone" but not here. i have written my code in c#.
also what does this mean" positive integer K of not more than 1000000 digits" what is maxm value of K?
2016-04-02 17:59:03
What happens if input integer is written with the beginning zero(s)? For example: 01010
2016-04-02 14:30:19
please upgrade your fucking compilers in c atoi not working!
2016-03-26 13:44:58
For those getting wrong answer it is probably because your code wont work for a large( e.g. : 100 )digit number
2016-03-23 22:19:20
check for the following:
1900:1991,1991:2002,191:202
2016-03-20 11:53:27
it says wrong answer even though it runs perfectly locally and on ideone and aviben yes i checked for input 1010 the output was 1111,i can't figure out the problem
2016-03-17 18:42:18
[17/03/16] works locally and on ideone.. but WA here..
[25/02/17] finally solved .. learnt so much..

Last edit: 2017-02-28 20:27:12
2016-03-17 17:39:37
cleared from todolist after a long time. :D
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.