/* ***********************************************
Author :PeterBishop
Created Time :Sun 17 Feb 2019 22:47:11 CST
File Name :t.cpp
Origin :P O J 1308
************************************************ */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
struct node{
int f;
}T[10001];
void init(){
for(int i=1;i<=10001;i++)
T[i].f=i;
}
bool judge(int a,int b){
if(T[b].f!=b)
return false;
T[b].f=a;
return true;
}
int main()
{
//freopen("out.txt","w",stdout);
//freopen("in.txt","r",stdin);
int k=0;
int a,b;
bool flag;
while(cin>>a>>b){
if(a<0)
break;
k++;
init();
int c,d;
flag=judge(a,b);
while(cin>>c>>d){
if(c==0&&d==0)
break;
flag=judge(c,d);
if(!flag){
while(cin>>c>>d)
if(c==0)
break;
break;
}
}
if((c==0)|!flag){
if(flag)
cout<<"Case "<<k<<" is a tree."<<endl;
else
cout<<"Case "<<k<<" is not a tree."<<endl;
}
}
return 0;
}