@Override
    protected void execute(Scanner in, PrintStream out) {
        for (int display = in.nextInt(); display != 0; display = in.nextInt()) {
            LedNumber.reset();

            out.print("Case <" + display);
            LedNumber.breakDisplay(display);
            for (display = in.nextInt(); display != 0; display = in.nextInt()) {
                out.print("," + display);
                LedNumber.breakDisplay(display);
            }
            out.print(">:");

            List<LedNumber> numbers = new ArrayList<>(Arrays.asList(LedNumber.values()));
            while (!numbers.isEmpty()) {
                LedNumber number = numbers.remove(0);
                boolean matched = false;
                for (Iterator<LedNumber> iter = numbers.iterator(); iter.hasNext(); ) {
                    LedNumber led = iter.next();
                    if (led.confusable(number)) {
                        if (!matched) out.print(" {" + number);
                        matched = true;
                        out.print("," + led);
                        iter.remove();
                    }
                }
                if (matched) out.print("}");
            }

            out.println();
        }
    }