package fixjava;

public class StringUtils {

	/** Repeat the given string the requested number of times. */
	public static String repeat(String str, int numTimes) {
		StringBuilder buf = new StringBuilder(Math.max(0, str.length() * numTimes));
		for (int i = 0; i < numTimes; i++)
			buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the left hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padLeft(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(padChar);
		for (int i = 1, mi = bufSize - str.length(); i < mi; i++)
			buf.append(padChar);
		buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the right hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padRight(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(str);
		buf.append(padChar);
		while (buf.length() < bufSize)
			buf.append(padChar);
		return buf.toString();
	}

	/** Intern all strings in an array, skipping null elements. */
	public static String[] intern(String[] arr) {
		for (int i = 0; i < arr.length; i++)
			arr[i] = arr[i].intern();
		return arr;
	}

	/** Intern a string, ignoring null */
	public static String intern(String str) {
		return str == null ? null : str.intern();
	}

}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package googlecodejam2012_qualification;
import java.io.*;
import java.util.*;
/** 
 * @author neil
 */
public class NewMain2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)  throws IOException
    {         
        //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));   
        BufferedReader in = new BufferedReader(new FileReader("C:\\Documents and Settings\\neil\\Desktop\\C-large.in"));        
        BufferedWriter out = new BufferedWriter(new FileWriter("C:\\Documents and Settings\\neil\\Desktop\\C-large-output.txt"));
        PrintStream ps = new PrintStream(System.out,true);
        StringTokenizer st;//st = new StringTokenizer(in.readLine()," ");
        int t = Integer.parseInt(in.readLine());
        int count=0,count1=0;
        while(count++<t)
        {
            count1=0;
            st = new StringTokenizer(in.readLine()," ");
            int A = Integer.parseInt(st.nextToken());
            int B = Integer.parseInt(st.nextToken());
            //boolean n[] = new boolean[B+1];
            for(int i=A;i<=B;i++)
            {
                String N = Integer.toString(i);
                 ArrayList<String> hey = new ArrayList<String>();
                for(int j=1;j<N.length();j++)
                {
                   
                    N = N.substring(N.length()-1)+N.substring(0,N.length()-1);
                    if(!N.startsWith("0")&&(Integer.parseInt(N)>=A&&Integer.parseInt(N)<i)&&!hey.contains(N))
                    {
                        hey.add(N);
                        //System.out.println(N+" : "+i);
                        count1++;                                                
                    }                    
                }                            
            }                                                        
            
            ps.println("Case #"+count+": "+count1);
            out.write("Case #"+count+": "+count1+"\n");
            out.flush();
        }   
       
       
    }
}
