program cojs1636;
var
a:array[0..85]of longint;
count,root,l,r,i:longint;
procedure build(root,k:longint);
var
x:longint;
begin
inc(a[k],root);
if k<l then l:=k;
if k>r then r:=k;
read(x);
if x<>-1 then build(x,k-1);
read(x);
if x<>-1 then build(x,k+1);
end;
begin
assign(input,'leaves.in');reset(input);
assign(output,'leaves.out');rewrite(output);
while not eof do
begin
read(root);
if root=-1 then
begin
readln;
continue;
end;
fillchar(a,sizeof(a),0);
inc(count); l:=40; r:=40;
build(root,40);
writeln('Case ',count,':');
for i:=l to r-1 do
write(a[i],' ');
writeln(a[r]);
writeln;
readln;
end;
close(input);close(output);
end.