CIVIC DILL MIX

Time limit1sMemory limit128 MB

Problem

Roman numerals are an ancient numbering system that was used throughout Europe until the 13th century, when it was gradually replaced by our current positional system. Traces of it still survive today on clock faces, building cornerstones, Super Bowl numbers, and Star Wars episode numbers. The system uses these 7 symbols:

SymbolIVXLCDM
Value1510501005001000

The symbols I, X, C, and M may be repeated as needed (but never more than three times for I, X, and C). So 3 is written as III, 27 as XXVII, and 4865 as MMMMDCCCLXV. Symbols are normally written from the highest value to the lowest, with one exception: when a smaller symbol appears immediately before a larger one, it is subtracted from the larger. Thus 4 is written as IV rather than IIII, and 900 as CM.

The rules for this subtractive form are:

  1. Only I, X, and C can be subtracted.
  2. A symbol may appear only once in its subtractive form (for example, you cannot write 8 as IIX).
  3. Each subtracted symbol may only come before a symbol at most 10 times its own value. So 99 cannot be written as IC nor 490 as XD (they are XCIX and CDXC). Note that the first two words of this problem's title are invalid Roman numerals, but the third one is valid.

Your task is simple: read a set of Roman numeral values and output their sum as a Roman numeral.

Input

The input consists of multiple test cases. Each test case begins with a positive integer $n$, the number of values to add. The $n$ values follow (possibly several per line); they are all valid Roman numerals, separated only by whitespace. A value of $n = 0$ marks the end of the input. Every sum is less than 5000.

Output

For each test case, print one line in the format Case c: s, where $c$ is the test-case number written as a Roman numeral (numbering starts at I) and $s$ is the sum written as a Roman numeral. Each Roman numeral must be written in the standard form described above — symbols from the highest value to the lowest, using the subtractive forms (IV, IX, XL, XC, CD, CM) wherever they apply — which gives a unique representation of every value.