#include <bits/stdc++.h>

#define sum(i) ((i & 0xf) + ((i >> 4) & 0xf) + ((i >> 8) & 0xf) + ((i >> 12) & 0xf) + ((i >> 16) & 0xf) + ((i >> 20) & 0xf)) 
#define print(i) cout << (((i) >> 20) & 0xf) << ' ' << (((i) >> 16) & 0xf) << ' ' << (((i) >> 12) & 0xf) << ' ' << (((i) >> 8) & 0xf) << ' ' << (((i) >> 4) & 0xf) << ' ' << ((i) & 0xf) << '\n'
using namespace std;

char type;
int forward_a[15504];
int backward[16777216];
int case_num;
int main() {
        int index = 0;
        for (int i = 0; i < 16777216; i++) {
                
                if (sum(i) == 15) {
                        forward_a[index++] = i;
                        backward[i] = index - 1;
                }
        }

        while (cin >> type && type != 'e') {
                cout << "Case " << ++case_num << ": ";
                if (type == 'm') {
                        int a;
                        int code = 0;
                        for (int i = 0; i < 6; i++) {
                                cin >> a;
                                code |= (a << ((5 - i) * 4));
                        }
                        cout << backward[code] << '\n';
                }
                if (type == 'u') {
                        int index;
                        cin >> index;
                        print(forward_a[index]);
                }
        }

        return 0;
}