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


hide comments
Ramon: 2014-10-06 00:48:18

I need some help, please. My code runs fine in my machine but gets a WA. Can someone post a good set of test cases, please?

Abhay: 2014-10-04 20:12:33

I am getting WA. Can anyone provide me with some sample test cases?
Thanks

karan: 2014-10-04 08:14:38

nice problem on string parsing :)

Apurva Priyadarshi: 2014-10-04 00:09:30

@rubal gupta pes college wapas aao tab bata denge

RUBAL GUPTA: 2014-09-27 22:47:10

@calor: i saw that yu have done this code plz help me out for this code alse plz give me the gmail id






;

Mayuri: 2014-09-26 16:37:55

what is meant do not display leading zeroes can you give an example what is leading zeroes?

shikhil gupta: 2014-09-25 12:08:28

<snip>

Last edit: 2022-07-26 22:28:54
sachin: 2014-09-24 21:38:18

give some inputs and their outputs
to check program

Pawan Bathe: 2014-09-23 22:42:39

Can anybody help understand, why is this wrong <snip>

Last edit: 2022-07-26 22:28:47
Huibert-Jan Nieuwkamer: 2014-09-23 11:41:49

Although it has been said before: For all of you lot using python and sys.stdin.readline(), use input() (or raw_input() depending on python #) instead to read input. The last line has no line ending character.


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

Problem's scores 1 vote

Concept difficulty
Concept difficulty 37%
Implementation difficulty
Implementation difficulty 50%
468 16