// Guillermo Gomez
// Solution to 2007 World Finals Problem B: Containers
import java.util.*;
import java.io.*;

public class containers{
	
	public static void main(String[] args) throws IOException{
		
		Scanner fin = new Scanner(new File("containers.in"));
		String stack;
		int res, n, cur, kase = 1;
		int[] top;
		
		while(true){
			
			// Exit condition.
			stack = fin.next();
			if(stack.compareTo("end")==0)break;
			
			n = stack.length();
			
			// Number of stacks used so far.
			res = 0;
			top = new int[26];
			
			// Go through each character in the string.
			outer:
			for(int i = 0; i < n; i++){
				cur = (stack.charAt(i) - 'A');
			
				// Try placing this letter on top of each stack.
				for(int j = 0; j < res; j++)
					
					// Go ahead and put it here, since this is the
					// "earliest" stack up which this letter fits.
					if(cur <= top[j]){
						top[j] = cur;
						continue outer;
					}
					
				// This letter fit on no stack, so make a new one.
				top[res++] = cur;
			}
			
			System.out.println("Case "+(kase++)+": "+res);
		}
	}
}