#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=100000;
int sum[maxn];//
void build(int p){
int v;
cin>>v;
if(v==-1) return;
sum[p]+=v;
build(p-1);
build(p+1);
}
bool init(){
int v;
cin>>v;
if(v==-1) return false;
memset(sum,0,sizeof(sum));
int p=maxn/2;
sum[p]=v;
build(p-1);
build(p+1);
return true;
}
int main(){
int kase=0;
while(init()){
int p=0;
while(sum[p]==0) p++;//寻找最左边树叶
cout<<"Case "<<++kase<<":\n"<<sum[p++];//先输出第一个元素 方便最后一个元素后面不带空格
while(sum[p]!=0)
cout<<" "<<sum[p++];
cout<<"\n\n";
}
return 0;
}