/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package recycled;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.TreeSet;

/**
 *
 * @author Alfred
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    try {
            FileInputStream fstream = new FileInputStream("C-small-attempt0.in");
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            FileWriter outFile = new FileWriter("out.txt");
            PrintWriter out = new PrintWriter(outFile);
            String line;
            line = br.readLine();
            int cases = Integer.parseInt(line);
            for (int i=1; i<=cases;i++){
                line = br.readLine();
                String[] values = line.split(" ");
                int A = Integer.parseInt(values[0]);
                int B = Integer.parseInt(values[1]);
                int total=0;
                for (int n=A; n<=B;n++){
                    TreeSet<String> solutions = new TreeSet<String>();
                    for (int k=1;k<values[1].length();k++){
                        String m = circshift(n,k);
                        int mVal = Integer.parseInt(m);
                        if(mVal<=B && mVal!=n  && mVal> n && !m.startsWith("0") && m.length()==Integer.toString(n).length() )
                        {
                            solutions.add(m);
                        }                   
                    }
                    total+=solutions.size();
                }
                out.println("Case #"+i+": "+total);
            }
            in.close();
            out.close();
        } catch (Exception e) {//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }

}

    private static String circshift(int n, int k) {
        String nString=Integer.toString(n);
        int len=nString.length();
        String m =  nString.substring(len-k)+nString.subSequence(0, len-k);
        //System.out.println(n+" "+m);
        return m;
    }

}

package qual;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public class C {

	public static int[] prepare(int m, int base, int k){
		int[] res = new int[m];
		for (int i = 0; i < m; i++){
			int rest = k % 10;
			k /= 10;
			k += rest * base;
			res[i] = k;
		}
		return res;
	}
	public static void main(String[] args) throws Exception{
		String in_file = "q/c/s_in.txt";
		String out_file = in_file.replace("_in.txt", "_out.txt");
		BufferedReader in = new BufferedReader(new FileReader(in_file));
		BufferedWriter out = new BufferedWriter(new FileWriter(out_file));
		
		int n = Integer.parseInt(in.readLine());
		for (int i = 1; i <= n; i++){
			String[] s = in.readLine().split(" ");
			int a = Integer.parseInt(s[0]);
			int b = Integer.parseInt(s[1]);

			int count = 0;
			int base = 1;
			int m = 0; 
			while (base * 10 <= a) {
				base *= 10;
				m++;
			}
			for (int k = a; k < b; k++){
				int[] prob = prepare(m, base, k);
				for (int p : prob){
					if (p > k && p <= b) count++;
				}
			}
			out.write("Case #" + i + ": " + count + "\n");
		}
		
		in.close();
		out.close();
	}

}
