1. 


/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10591 (Happy Number)
* Link: http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=17&page=show_problem&problem=1532
*
* @author Florian Lermer, Umut Taskin, Hidir Sayli
* @version 1.0, 03/31/2009
*
* Status : Accepted
* Runtime: 0.300
*/

import java.util.Scanner;

public class Main {

public static String digitSum(String str) {
int sum = 0, d;
for(int i = 0; i < str.length(); i++) {
d = (str.charAt(i) - '0');
sum += (d * d);
}
return ("" + sum);
}

public static void main(String[] args) {

Scanner in = new Scanner(System.in);
String N, n;
int c;
int p = 1;

c = in.nextInt();

for(int a = 0; a < c; a++) {
N = in.next();
n = digitSum(N);
while(n.length() != 1) {
n = digitSum(n);
}
if(n.equals("1") == true) {
System.out.println("Case #" + p++ + ": " + N + " is a Happy number.");
}
else {
System.out.println("Case #" + p++ + ": " + N + " is an Unhappy number.");
}
}
}


}