#include <iostream>
#include <map>
#include <array>



using namespace std;

void decrementDist(array<int,6> & dist);

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

    array<int,6> distribution = {15,0,0,0,0,0};

    struct TwoWayMap {

        map< array<int,6>,int> dist2number;
        map<int, array<int,6>> number2dist;


        int getNumber (array<int,6> place){
            return dist2number[place];
        }

        array<int,6> getDist (int place){
            return number2dist[place];
        }

        void add (array<int,6> dist, int number){
            dist2number[dist] = number;
            number2dist[number] = dist;
        }
    };

    TwoWayMap doublemap;

    for (int i = 15503; i > 0; --i) {
        doublemap.add(distribution,i);
        decrementDist(distribution);
    }
    doublemap.add(distribution,0);

    array<int, 6> input;
    array<int, 6> output;
    string prompt;
    int Case = 1;
    cin >> prompt;
    while (prompt != "e"){
        if (prompt == "m"){

            cin >> input[0];
            cin >> input[1];
            cin >> input[2];
            cin >> input[3];
            cin >> input[4];
            cin >> input[5];

            cout << "Case " << Case << ": " << doublemap.getNumber(input) << endl;

        }else{

            int n;
            cin >> n;
            output = doublemap.getDist(n);
            cout << "Case " << Case << ": " << output[0] << " " << output[1] << " " << output[2] << " " << output[3] << " " << output[4] << " " << output[5] << endl;

        }
        Case++;
        cin >> prompt;
    }


    return 0;
}


void decrementDist(array<int,6> & dist){
    int i = 5;
    while(dist[i] == 0){
        i--;
    }

    if (i == 5){
        int count = dist[i];
        dist[i] = 0;
        i--;
        while(dist[i] == 0){
            i--;
        }
        dist[i] = dist[i] - 1;
        dist[i+1] = dist[i+1] + 1 + count;

    }
    else{
        dist[i] = dist[i] - 1;
        dist[i+1] = dist[i+1] + 1;
    }
    return;
}