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
kannanmk07: 2024-12-19 13:21:29

fck yes solved it using java

tweakmonkey: 2024-09-29 22:21:28

For anyone stuck getting wrong answer - try this input:
2
1234567887654322
12345678987654322

It should output:
1234567997654321
12345679097654321

carofe82: 2024-08-10 16:16:24

This was a weird problem. @shreyas_07 test cases helped a lot!

puppetmaster: 2024-06-25 10:08:00

was getting wrong answer forever @shreyas_07 tcs saved me

temurjon_01: 2024-03-07 09:55:53

what a fuck is that spoj find another compiler i did anything right and again "WRONG ANSWER".

rayhanulislam: 2023-12-15 17:08:01

how much test case?

dwind11: 2023-11-06 09:18:11

gg

sleepyslash: 2023-07-02 12:02:44

my code is all fine and working very well in my compiler the same file giving a runtime error in spoj judge why ???
my code : <snip>
can anyone tell whats wrong

[Simes]: this is not the place for code review, use the forum.

Last edit: 2023-07-02 12:05:41
jmdalida11: 2023-02-16 12:17:09

I solved it using rust <3

fjkexgnffhwihp: 2022-06-20 17:09:50

Why is the implementation difficulty so high? I found it to be pretty easy in both concept and implementation in CPP14


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