/*
 * 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;
    }

}

import java.util.*;
import java.io.*;

public class C
{
	public static int roll (int i, int a, int b)
	{
		int found = 0;
		int digits = (""+i).length();
		
		int[] vit = new int[digits];
		
		int magic;
		
		int keep, move,done;
		
		
		for (int d = 1; d < digits; d++)
		{
			magic = (int)Math.pow(10, d);
			keep = i/magic;
			move = i%magic;
			magic = (int)Math.pow(10, digits-d);
			done = keep + (move * magic);
		
			
			if (a <= done && done <= b && done < i)
			{
				vit[found] = done;
				found++;
			}
		}
		
		if (found > 1) 
		{
			Arrays.sort(vit);
			for (int j = 0; j < vit.length - 1; j++)
				if (vit[j] != 0 && vit[j] == vit[j+1])
					found--;
		}
		return found;
	}

	public static void main(String... args) throws Exception
	{
		BufferedReader in = new BufferedReader (new FileReader( "C-small-attempt0.in" ));
		
		String line;
		in.readLine(); 
		int casenum = 1;

		int a,b;
			
		String[] nums;
		while ( (line = in.readLine()) != null)
		{
			nums = line.split(" ");
			
			a = Integer.valueOf(nums[0]);
			b = Integer.valueOf(nums[1]);
			
			int result = 0;
			for (int m = a; m <= b; m++)
				result += roll(m,a,b);
	
			System.out.println("Case #" + casenum + ": " + (result));
			casenum++;
		}
	}
}