program dgh;
const maxn=100;
var sum:array[1..maxn]of longint;
kase,p,tot:longint;
procedure build(p:longint);
var v:longint;
begin
read(v);
if v=-1 then exit;
sum[p]:=sum[p]+v;
build(p-1);
build(p+1);
end;
function init:boolean;
var v,pos:longint;
begin
if tot<>0 then readln
else tot:=tot+1;
read(v);
if v=-1 then begin init:=false;exit;end;
fillchar(sum,sizeof(sum),0);
pos:=maxn div 2;
sum[pos]:=v;
build(pos-1);
build(pos+1);
end;
begin
assign(input,'leaves.in');reset(input);
assign(output,'leaves.out');rewrite(output);
kase:=0;tot:=0;
while(init()) do
begin
p:=0;
while(sum[p]=0)do inc(p);
kase:=kase+1;
writeln('Case ',kase,':');
write(sum[p]);
p:=p+1;
while(sum[p]<>0)do
begin
write(' ',sum[p]);
p:=p+1;
end;
writeln;
writeln;
end;
close(input);
close(output);
end.