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-09-22 20:33:12
If it's something else then let me know.

Last edit: 2016-09-22 20:34:40
2016-09-22 20:33:12
@malavan i Think if you entered a single digit number less than 9, the next palindrome would be that number + 1, according to the palindrome definition.
2016-09-22 15:23:33
if the input is single digit ,is that output will be 11 ????
2016-09-13 16:06:34
@imad315: It's the no. of times your code will be run for different sets of input.
In code: main() {
int noOfTestcases; cin >> noOfTestcases;
for(int i=1; i<=noOfTestcases; i++)
{
// write the actual code that solves each testcase
}
} // end of main
2016-09-05 12:52:01
NZEC java....
2016-09-03 22:21:19
What wrong with this compiler? My solution dont accept every time but on VS it is running smoothly ((
2016-09-01 09:39:34
My JAVA code is working fine in Ideone and eclipse but here i am getting NZEC everytime , i have used the stringbuilder is that a problem?
2016-08-31 18:23:37
I got the right output but when i submit the solution, it says wrong answer. Can there be a problem with " given positive integer K of not more than 1000000 digits," ? I've used long long int for that. Please help.
2016-08-31 09:42:01
what is constraints of test cases.
0<t<?

2016-08-30 14:13:11
Finally AC after too much hard work!!!
Run your code for small number like one digits numbers especially 9
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.