#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main () {
	int configs[15504][6]; //={0} 
	//last config:
	configs[15503][0] = 15;
	configs[15503][1] = 0;
	configs[15503][2] = 0;
	configs[15503][3] = 0;
	configs[15503][4] = 0;
	configs[15503][5] = 0;

	//compute/find lexicographically largest config < last config
	for (int i=15502; i>=0; i--) {
		//copy last config
		for (int k=0; k<6; k++)
			configs[i][k] = configs[i+1][k];

		//Normal transition [..k..,x,0,y] => [..k..,x-1,1,y]
		//Special Transition: [..0.. x, ...] => [..0.., x-1, 15-(x-1), ..0..]

		int k;
		for (k=4; k>=0; k--) {
			if (configs[i][k] != 0)
				break; //from last config, find loc'n of rightmost nonzero pos out of configs[x][0...4]
		}

		//then shift right, incrementally:: CORRECT, more clear.
		configs[i][k]--;
		configs[i][k+1]++;
		if (k < 4) { //shift items up to get lexicographical largest!
			configs[i][k+1] += configs[i][5];
			configs[i][5] = 0;
		}

		//ALSO CORRECT
		/*if (k < 4) {
			configs[i][k]--;
			configs[i][k+1] += (1+configs[i][5]);
			for (int rest = k+2; rest<6; rest++)
				configs[i][rest] = 0;
		} else {
			configs[i][k]--;
			configs[i][k+1]++;
		}*/


		/* WRONG! => REAL, CORRECT rule:
			Add # from last column to the destination of shift!
		*/
		//BUG: 1,0,0,10,0,4 => 1,0,0,9,5,0 (expected), 1,0,0,9,1,4 (actual)
		/*if (k == leftmost && configs[i][k]!=15) { //Ex: 0,1,0,0,0,14 => 0,0,15,0,0,0 => 0,0,14,1,0,0 (ugly transition)
			configs[i][k]--;
			configs[i][k+1] = 15-configs[i][k];
			for (int rest = k+2; rest<6; rest++)
				configs[i][rest] = 0;
			if (configs[i][k] == 0) leftmost++; //shift leftmost marker
		} else {
			configs[i][k]--;
			configs[i][k+1]++;
		}*/
		
		//WRONG!!
 		//(BUG: Too specific, the transition is MORE general!) EDGE CASE: [..1.., 14] => [...15., 0]; NOT [...1., 14] 
		/*if (configs[i][5] == 14 && k<4) {
			//assert(configs[i+1][k] == 1);
			configs[i][k] = 0;
			configs[i][k+1] = 15;
			configs[i][5]=0; //This is edge case if k==4
		} else if (configs[i][5] == 14 && k==4) {
			//assert(configs[i+1][k] == 1);
			configs[i][k] = 0;
			configs[i][k+1] = 15;
		} else {
			configs[i][k]--;
			configs[i][k+1]++;
		}*/
	}

	for (int i=1;  ;i++) {
		char type;
		cin >> type;
		if (type == 'e') {
			break;
		} else if (type == 'm') {
			int pattern[6];
			for (int k=0; k<6; k++)
				cin >> pattern[k];
			//linear search pattern in table
			for (int x=0; x<15504; x++) {
				bool matches = true;
				for (int k=0; k<6; k++) {
					matches = matches && (configs[x][k] == pattern[k]);
				}
				if (matches) {
					cout << "Case " << i << ": " << x << endl;
					break;
				}
			}			

		} else if (type == 'u') {
			int ind;
			cin >> ind;

			cout << "Case " << i << ":";
			for (int k=0; k<6; k++)
				cout << " " << configs[ind][k];
			cout << endl;
		} else {
			
		}
	}

}