Server Time: Mon Oct 26, 2020 6:18 am
Welcome ( logout
B - Palindromic Numbers (III)
PDF (English) Ranklist
Time Limit: 1 second(s) Memory Limit: 32 MB

Vinci is a little boy and is very creative. One day his teacher asked him to write all the Palindromic numbers from 1 to 1000. He became very frustrated because there is nothing creative in the task. Observing his expression, the teacher replied, "All right then, you want hard stuff, you got it." Then he asks Vinci to write a palindromic number which is greater than the given number. A number is called palindromic when its digits are same from both sides. For example: 1223221, 121, 232 are palindromic numbers but 122, 211, 332 are not. As there can be multiple solutions, Vinci has to find the number which is as small as possible.


Input starts with an integer T (≤ 30), denoting the number of test cases.

Each case starts with a line containing a positive integer. This integer can be huge and can contain up to 105 digits.


For each case, print the case number and the minimum possible palindromic number which is greater than the given number.

Sample Input

Output for Sample Input







Case 1: 131

Case 2: 2

Case 3: 1333331

Case 4: 22

Case 5: 1221


Dataset is huge, use faster I/O methods.

Problem Setter: S. M. Ijaz-ul-Amin Chowdhury
Special Thanks: AKM Mubashwir Alam
Developed and Maintained by
Copyright © 2012
LightOJ, Jane Alam Jan