spoj#ACFRAC. Another Continuous Fractions Problem

Another Continuous Fractions Problem

The problem description is the same as the problem CFRAC and CFRAC2.

Input & Output

Multiple test cases, a single line with a single uppercase character C indicates the end of the input. The number of test cases will be less than 1000.

For each test case:

The first line of the input contains a single uppercase character A or B.A denotes that the input following character A and output format of this test case is the same as problem CFRAC, otherwise the input following character B and output format of this test case is the same as problem CFRAC2. But please pay attention that: the width and the height of the image after the character B will not appear in the input; the original fraction will not appear in the output of the test case of type A.

The example will make everything clear.

Example

Input:
A
75 34
B
..........1......
2.+.-------------
............1....
....4.+.---------
..............1..
........1.+.-----
................1
............5.+.-
................1
C

Output: Case 1: ..........1...... 2.+.------------- ............1.... ....4.+.--------- ..............1.. ........1.+.----- ................1 ............5.+.- ................1 Case 2: 75 34

</p>