// Arup Guha
// 7/20/2013
// Solution to 2012 East Central Regional Problem D: I've got your back(gammon).

import java.util.*;

public class d {

	// Used to store all cases.
	public static int index;
	public static String[] table;
	public static HashMap<String,Integer> map;

	// Relevant constants.
	final public static int SIZE = 15504;
	final public static int ARRAY_SIZE = 6;
	final public static int TOTAL_SUM = 15;

	public static void main(String[] args) {

		// Set up storage of all numbers.
		table = new String[SIZE];
		map = new HashMap<String,Integer>();
		index = 0;

		// Solve all combos mapped to ints.
		int[] combo = new int[ARRAY_SIZE];
		rec(combo, 0, 0);

		Scanner stdin = new Scanner(System.in);

		String command = stdin.next();
		int loop = 1;

		// Go through each case.
		while (!command.equals("e")) {

			// Go from array to number.
			if (command.equals("m")) {
				int[] vals = new int[ARRAY_SIZE];
				for (int i=0; i<ARRAY_SIZE; i++)
					vals[i] = stdin.nextInt();
				System.out.println("Case "+loop+": "+map.get(makeStr(vals)));
			}

			// Go from number to array.
			else {
				int val = stdin.nextInt();
				System.out.println("Case "+loop+": "+table[val]);
			}

			command = stdin.next();
			loop++;
		}

	}

	// Fills all combos that currently add up to curSum starting to fill at index k.
	public static void rec(int[] combo, int curSum, int k) {

		// Add our solution.
		if (curSum == TOTAL_SUM) {
			String s = makeStr(combo);
			table[index] = s;
			map.put(s, index);
			index++;
			return;
		}

		// No solution in this case.
		if (k == ARRAY_SIZE) return;

		// Try putting each number in numerical order in slot k.
		for (int i=curSum; i<=TOTAL_SUM; i++) {
			combo[k] = i - curSum;
			rec(combo, i, k+1);
			combo[k] = 0;
		}
	}

	// Return a string form.
	public static String makeStr(int[] combo) {
		String s = "" + combo[0];
		for (int i=1; i<combo.length; i++)
			s = s + " " + combo[i];
		return s;
	}
}