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
2014-12-06 23:58:21 Dawid
Hi guys, why does it say "compilation problem" while ideone runs it smooth? (C++).
2014-12-04 04:03:34 asitm9
@Jasdeep: check for 10. It should be 11.

Last edit: 2014-12-04 04:04:15
2014-12-03 22:59:22 gamer496
@admin could you check my solution i'm
getting wa even after checking all the corner cases
id 13050031
ideone <snip>
@asitm9 thank you for you test case finally submitted


Last edit: 2022-07-26 22:29:05
2014-12-03 09:55:22 asitm9
AC in 3rd GO... :)

Last edit: 2014-12-04 03:53:09
2014-12-03 09:38:20 Mayank Ladia
Finally.. :') just coz of array size cost me 3 ..
2014-11-27 09:28:45 Minsuk Kim
Nice problem - a hint is to think about the cases for the odd number of digits and even number of digits separately
2014-11-19 04:10:12 Rafael Cunha de Almeida
I can't figure out which number is breaking my code :( I've made a test case of thousands of random numbers and they all passed. I'm out of ideas :(
2014-11-18 12:23:02 NPR
Hi! I want to know if anybody can send to me a list with all cases of input ? My problem is that I'm not sure if input can be for example: 005 and if it can, which is the next palindrome ? 6 or 101 ? Thank you
2014-11-10 21:44:08 HARSH MADHOGARIA
<snip>
cnt find the mistake please help!!!

Last edit: 2022-07-26 22:28:58
2014-11-07 10:03:50 kp
Ans for 000000 should have been 1 or 11 but its different..showing with toolkit!! anybody to explain??
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.