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

inline int M(int a, int b, int c, int d, int e, int f)
{
    return a * 16 * 16 * 16 * 16 * 16 + b * 16 * 16 * 16 * 16 + c * 16 * 16 * 16 + d * 16 * 16 + e * 16 + f;
}

int main()
{
    unordered_map<int, int> A;
    vector<int> B;
    for (int a = 0; a <= 15; a++)
    for (int b = 0; b <= 15; b++)
    for (int c = 0; c <= 15; c++)
    for (int d = 0; d <= 15; d++)
    for (int e = 0; e <= 15; e++)
    for (int f = 0; f <= 15; f++)
    {
        if(a + b + c + d + e + f != 15) continue;
        int m = M(a, b, c, d, e, f);
        A[m] = A.size() - 1;
        B.push_back(m);
    }
 
    
    int t = 0;
    while (1)
    {
        char m; cin >> m;
        if (m == 'e') break;
        
        cout << "Case " << ++t << ":";
        
        if (m == 'm')
        {
            int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
            cout << " " << A[M(a, b, c, d, e, f)] << endl;
        }
        else
        {
            int a; cin >> a;
            a = B[a];
            int c = 16 * 16 * 16 * 16 * 16;
            for (int i = 0; i < 6; i++)
            {
                cout << " " << a / c;
                a -= a / c * c;
                c /= 16;
            }
            cout << endl;
        }
    }
}