// dpoeschl import java.util.*; public class DBackgammon { static HashMap m = new HashMap(); static HashMap u = new HashMap(); public static void main(String[] args) { Scanner scan = new Scanner(System.in); createMaps(); int icase=0; while (true) { String line = scan.nextLine(); if (line.startsWith("e")) return; System.out.println("Case " + ++icase + ": " + (line.startsWith("m") ? m : u).get(line.substring(2))); } } static void createMaps() { int[] array = new int[] { 0, 0, 0, 0, 0, 15 }; save(0, array); for (int i = 1; i < 15504; i++) nextAndSave(i, array); } static void nextAndSave(int pos, int[] a) { for (int p = 5; p > 0; p--) { if (a[p] > 0) { a[p - 1]++; int t = a[p] - 1; a[p] = 0; a[5] = t; save(pos, a); return; } } } static void save(int pos, int[] a) { String s = String.format("%d %d %d %d %d %d", a[0], a[1], a[2], a[3], a[4], a[5]); String p = Integer.toString(pos); m.put(s, p); u.put(p, s); } }