#include <iostream>
using namespace std;
int main()
{
int n,m,k=0,s[100005]={0},j=0,i,big;
bool f=0;
bool flag[100005]={0};
while(cin>>n>>m)
{
if(m==-1&&n==-1)return 0;
if(m==0&&n==0)
{
k++;
int c=0;
for(i=1;i<=big;i++){if(flag[i]){c++;flag[i]=0;s[i]=0;}}
if(f) cout<<"Case "<<k<<" is not a tree."<<endl;
else if(c==0)cout<<"Case "<<k<<" is a tree."<<endl;
else if(c!=j+1)cout<<"Case "<<k<<" is not a tree."<<endl;
else cout<<"Case "<<k<<" is a tree."<<endl;
j=0;
f=0;
big=0;
}
else
{
j++;
flag[n]=flag[m]=1;
if((m>n?m:n)>big)big=(m>n?m:n);
if(s[m]!=0&&s[m]!=n)f=1;
else s[m]=n;
}
}
return 0;
}