Sphere Online Judge

SPOJ Problem Set (classical)

5. The Next Palindrome

Problem code: PALIN

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 Kosowski
Date:2004-05-01
Time limit:9s
Source limit:50000B
Languages:All except: TECS

hide comments
2010-03-04 20:53:23 :D
"Saikat Debnath": single digit number is alway a palindrome.
"Andrew": Number of test cases isn't specified for all problems, but I had a very slow implementation and still made it in the time limit with ease. I would urge You try this one.
"praveen": I don't really understand Your question :/
2010-03-04 17:28:52 praveen
what is the output for numbers greater than 1000000
2010-01-26 18:38:25 Saikat Debnath
Is anything missing in the question?
What about single digit numbers?
2009-11-03 08:55:02 Andrew
How many test cases have people allowed for?
SPOJ System © 2008-2010 Sphere Research Labs. All Rights Reserved.