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

int T, I;
map<vector<int>, int> M1;
map<int, vector<int>> M2;
vector<int> V;

void dfs(int a, int b) {
  if (a == 5) {
    V[5] = b;
    M1[V] = I;
    M2[I] = V;
    ++I;
    return;
  }
  for (int i = 0; i <= b; ++i) {
    V[a] = i;
    dfs(a+1, b-i);
  }
}

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

  V.resize(6);
  dfs(0, 15);

  while (true) {
    ++T;
    string op; cin >> op;
    if (op == "e") {
      break;
    }
    cout << "Case " << T << ": ";
    if (op == "m") {
      vector<int> v = vector<int>(6);
      for (int i = 0; i < 6; ++i) {
        cin >> v[i];
      }
      cout << M1[v] << endl;
    } else {
      int v;
      cin >> v;
      vector<int> m = M2[v];
      cout << m[0];
      for (int i = 1; i < 6; ++i) {
        cout << " " << m[i];
      }
      cout << endl;
    }
  }

  return 0;
}