#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

#define endl '\n'

void split(const string &s, char delim, vector<string> &elems) {
    stringstream ss;
    ss.str(s);
    string item;
    while (getline(ss, item, delim)) {
        elems.push_back(item);
    }
}


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    split(s, delim, elems);
    return elems;
}

int main() {
	ios::sync_with_stdio(0);
	map<string,int> mm;
	map<int,string> mu;
	int index = 0;
	for (int a=0; a<16; a++) {
		string curr = "-" + to_string(a);
		for (int b=0; b<(16-a); b++) {
			string curr1 = curr + "-" + to_string(b);
			for (int c=0; c<(16-b-a); c++) {
				string curr2 = curr1 + "-" + to_string(c);
				for (int d=0; d<(16-c-b-a); d++) {
					string curr3 = curr2 + "-" + to_string(d);
					for (int e=0; e<(16-d-c-b-a); e++) {
						string curr4 = curr3 + "-" + to_string(e) + "-" + to_string(15-e-d-c-b-a);
						// cout << index;
						// cout << curr4 << endl;
						mm[curr4] = index;
						mu[index] = curr4;
						index++;
					}
				}
			}
		}
	}

	char c;
	int T = 1;
	while(cin >> c && c != 'e') {
		if (c == 'm') {
			string key = "";
			for (int i=0; i<6; i++) {
				int l; cin >> l;
				key = key + "-" + to_string(l);
			}
			// cout << key << endl;
			cout << "Case " << T << ": " << mm[key] << endl;
		} else {
			int key2; cin >> key2;
			string ans = mu[key2];
			// cout << key2 << " " << ans << endl;
			vector<string> ans2 = split(ans, '-');
			cout << "Case " << T << ":";
			for (int i=0; i<ans2.size(); i++) {
				cout << ans2[i] << " ";
			}
			cout << endl;
		}
		T++;
	}
	return 0;
}