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
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.
Output
For each case, print the case number and the minimum possible palindromic number which is greater than the given number.
Sample
Sample Input | Sample Output |
---|---|
5 121 1 1332331 11 1121 | Case 1: 131 Case 2: 2 Case 3: 1333331 Case 4: 22 Case 5: 1221 |
Notes
Dataset is huge, use faster I/O methods.