// Solution to Generalized Roman Numerals

import java.util.*;

public class romanBob {
  public static Scanner in;
  public static String input;
  public static int casenum;
  public static HashSet<Integer> values; // all possible values
  public static HashMap<String,HashSet<Integer>> lookup; // memo-ize

  public static void main(String[] args) throws Exception {
    in = new Scanner(System.in);
    casenum = 0;
    lookup = new HashMap<String,HashSet<Integer>>();
    while(true) {
      input = in.next();
      if (input.equals("0")) break;
      casenum++;
      values = solve(input);
      Integer[] v = values.toArray(new Integer[0]);
      Arrays.sort(v);
      System.out.print("Case " + casenum + ":");
//System.out.print(" "+input+" ");
      for (int i : v)
        System.out.print(" "+ i);
      System.out.println();
    }
  }

  public static HashSet<Integer> solve(String s) throws Exception {
    HashSet<Integer> sol = new HashSet<Integer>();
    if (s.length() == 1)
      sol.add(decode(s));
    else {
      for (int i = 1; i < s.length(); i++) { 
   
        String lt = s.substring(0,i);
        String rt = s.substring(i);
        HashSet<Integer> left = lookup.get(lt);
        if (left == null) {
          left = solve(lt);
          lookup.put(lt,left);
        }
        HashSet<Integer> right = lookup.get(rt);
        if (right == null) {
          right = solve(rt);
          lookup.put(rt,right);
        }
         
        for (int l : left) {
          for (int r : right) {
            if (l < r)
              sol.add(r-l);
            else
              sol.add(r+l);
          }
        }
      }
    }
    return sol;
  }

  public static int decode(String s) throws Exception {
    if (s.equals("I")) return 1;
    else if (s.equals("V")) return 5;
    else if (s.equals("X")) return 10;
    else if (s.equals("L")) return 50;
    else if (s.equals("C")) return 100;
    else throw new Exception("Error in decode--no such numeral as "+s);
  }
}
