#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

vector<vector<int> > lol;
void dfs(vector<int> &curr, int sum) {
    if (curr.size() == 6) {
        if (sum == 15) {
            lol.push_back(curr);
        }
        return;
    }
    for (int i = 0; i <= 15-sum; i++) {
        curr.push_back(i);
        dfs(curr, sum+i);
        curr.pop_back();
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    vector<int> tmp;
    dfs(tmp, 0);
    sort(lol.begin(), lol.end());

    int csnum = 1;
    char c; cin >> c;
    while (c != 'e') {
        cout << "Case " << csnum << ":";
        if (c == 'm') {
            vector<int> combo;
            for (int i = 0; i < 6; i++) {
                int x; cin >> x; combo.push_back(x);
            }
            cout << " " << (lower_bound(lol.begin(), lol.end(), combo) - lol.begin()) << endl;
        } else {
            int z; cin >> z;
            for (int i = 0; i < 6; i++) {
                cout << " " << lol[z][i];
            }
            cout << endl;
        }
        cin >> c;
        csnum++;
    }
}