#include <bits/stdc++.h>

using namespace std;

int main()
{
  int testcase = 1;
  int N, B;
  while(scanf("%d %d", &N, &B), N) {
    vector< int > g[100000];
    for(int i = 1; i < N; i++) {
      int P;
      scanf("%d", &P);
      --P;
      g[P].emplace_back(i);
      g[i].emplace_back(P);
    }

    cout << "Case " << testcase++ << ":" << endl;

    if(N <= 2) {
      if(N == 1) cout << 1 << endl;
      else if(B == 1) cout << 2 << endl << 2 << endl;
      else cout << 1 << endl << 1 << endl;
      continue;
    }

    int root;
    for(int i = 0; i < N; i++) {
      if(g[i].size() >= 2) root = i;
    }

    vector< int > sz(N), dep(N), ans(N);

    function< void(int, int) > dfs1 = [&](int idx, int par)
    {
      int depmax = 1, size = 0;
      for(auto &to : g[idx]) {
        if(to != par) {
          dfs1(to, idx);
          if(depmax < dep[to]) depmax = dep[to], size = sz[to];
          else if(depmax == dep[to]) size += sz[to];
        }
      }
      if(size + 1 <= B) {
        sz[idx] = size + 1;
        dep[idx] = depmax;
      } else {
        sz[idx] = 1;
        dep[idx] = depmax + 1;
      }
    };


    function< void(int, int, int, int) > dfs2 = [&](int idx, int pardep, int parsz, int par)
    {
      map< int, int > vs;
      if(~par) vs[pardep] += parsz;
      for(auto &to : g[idx]) {
        if(to != par) vs[dep[to]] += sz[to];
      }
      const auto latte = prev(vs.end());
      if(latte->second + 1 <= B) ans[idx] = latte->first;
      else ans[idx] = latte->first + 1;

      for(auto &to : g[idx]) {
        if(to != par) {
          if(vs.find(dep[to]) == latte) {
            if(latte->second - sz[to] == 0) {
              assert(begin(vs) != latte);
              const auto malta = prev(latte);
              if(malta->second + 1 <= B) dfs2(to, malta->first, malta->second + 1, idx);
              else dfs2(to, malta->first + 1, 1, idx);
            } else {
              if(latte->second - sz[to] + 1 <= B) dfs2(to, latte->first, latte->second - sz[to] + 1, idx);
              else dfs2(to, latte->first + 1, 1, idx);
            }
          } else {
            if(latte->second + 1 <= B) dfs2(to, latte->first, latte->second + 1, idx);
            else dfs2(to, latte->first + 1, 1, idx);
          }
        }
      }
    };

    dfs1(root, -1);
    dfs2(root, 1, 0, -1);

    for(int i = 0; i < N; i++) {
      printf("%d\n", ans[i]);
    }
    fflush(stdout);

  }

}