#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
	unordered_map<string, int> map;
	unordered_map<int, string> ugh;
	stringstream ss;
	int index = 0;

	for(int a = 0; a <= 15; a++) {
		for(int b = 0; b <= 15 - a; b++) {
			for(int c = 0; c <= 15 - a - b; c++) {
				for(int d = 0; d <= 15 - a - b - c; d++) {
					for(int e = 0; e <= 15 - a - b - c - d; e++) {
						int f = 15 - a - b - c - d - e;
						ss << ' ' << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f;
						map.insert(make_pair(ss.str(), index));
						ugh.insert(make_pair(index, ss.str()));
						ss.str(string());
						index++;
					}
				}
			}
		}
	}

	char c; cin >> c;
	int tc = 1;

	do {
		if(c == 'm') {
			for(int i = 0; i < 6; i++) {
				int n; cin >> n;
				ss << ' ' << n;
			}
			cout << "Case " << tc << ": " << map.at(ss.str()) << endl;
			ss.str(string());
		}
		if(c == 'u') {
			int n;
			cin >> n;
			cout << "Case " << tc << ":" << ugh.at(n) << endl;
		}
		cin >> c;
		tc++;
	} while(c != 'e');

	return 0;
}