/* Problem 1--Digit Square Sums
   This one was straightforward.  Just run through the digits and
   perform the computation! */

import java.io.*;
import java.util.*;

public class prob1 {

 public static Scanner in=null;
 public static PrintWriter out=null;

 public static void main (String[] args) throws Exception {

  in = new Scanner (new File ("prob1.in"));
  out = new PrintWriter ("prob1.out");
  int n=0, cs=1;
  while ((n=in.nextInt())!=-1) {
   out.println ("Case "+(cs++));
   out.println (n);
   do {
    int t = 0;  // summing the squares of the digits
    while (n > 0) {
     t += (n%10)*(n%10);
     n /= 10;
    }
    n = t;
    out.println (n);
   } while (n!=1 && n!=4); // stopping when we get to 1 or 4.
   out.println ();
  }
  in.close();
  out.close();
 }
}
