#define happy 1#define unhappy 2intmain(intargc,charconst*argv[]){//1000000000//999999999//81*9 = 729intn[730]={0};n[1]=happy;for(inti=2;i<=729;i++){if(n[i]){continue;}set<int>tmp;tmp.insert(i);intsum=0;intg=i;boolb=false;do{sum=0;while(g){intr=g%10;sum=sum+r*r;g=g/10;}g=sum;if(!tmp.count(sum)){tmp.insert(sum);b=false;}else{b=true;break;}}while(sum!=1&&!b);if(sum==1){for(set<int>::iteratorit=tmp.begin();it!=tmp.end();it++){n[*it]=happy;}}else{for(set<int>::iteratorit=tmp.begin();it!=tmp.end();it++){n[*it]=unhappy;}}}intpp;while(scanf("%d",&pp)!=EOF){for(inti=1;i<=pp;i++){intuu;scanf("%d",&uu);inttmp=uu;intsum=0;while(uu){intr=uu%10;sum+=r*r;uu/=10;}if(n[sum]==happy){printf("Case #%d: %d is a Happy number.\n",i,tmp);}else{printf("Case #%d: %d is an Unhappy number.\n",i,tmp);}}}return0;}