import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Map<Integer,String> map1 = new HashMap<Integer,String>();
		Map<String, Integer> map2 = new HashMap<String, Integer>();
		int index = 0;
		for(int i = 0; i <= 15; i++){
			for(int j = 0; j <= 15 - i; j++){
				for(int k = 0; k <= 15 - i - j; k++){
					for(int l = 0; l <= 15 - i - j - k; l++){
						for(int o = 0; o <= 15 - i - j - k - l; o++){
							int left = 15 - i- j -k -l -o;
							String result = i + " " + j + " " + k + " " + l + " " + o + " " + left;
							map1.put(index, result);
							map2.put(result, index);
							index++;
						}
					}
				}
			}
		}
		
		Scanner scan = new Scanner(System.in);
		int cases = 1;
		String next = scan.next();
		while(!next.equals("e")){
			if(next.equals("m")){
				String find = "";
				find += scan.next() + " " + scan.next() + " " + scan.next() + " " + scan.next() + " " + scan.next() + " " + scan.next();
				System.out.println("Case" + " " + cases + ": " + map2.get(find));
				cases++;
			}
			else{
				int next2 = scan.nextInt();
				System.out.println("Case" + " " + cases + ": " + map1.get(next2));
				cases++;
			}
			next = scan.next();
		}
	}

}