
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;

public class Recycle
{
	public static void main(String[] args)
	{
/*		Set<Integer> perms = getPermutations(123456);
		
		for(Integer i: perms)
			System.out.println(i);*/
	
		try
		{
			Scanner s = new Scanner(new File("recycle.in"));
			BufferedWriter w = new BufferedWriter(new FileWriter(new File("recycle.out")));
			int numCases = s.nextInt();
			s.nextLine();
			
			for(int n = 1;n <= numCases; n++)
			{
				int A = s.nextInt();
				int B = s.nextInt();
				int count = 0;
				for(int k = A; k <= B; k++)
				{
					count += getNumPairs(k, B);
				}
				
				w.write("Case #" + n + ": " + count + "\n");
			}
			
			w.flush();
			w.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public static int getNumPairs(int n, int B)
	{
		Set<Integer> possibles = getPermutations(n);
		int count = 0;
		for(Integer i : possibles)
			if(i > n && i <= B)
				count++;
		return count;
	}
	
	public static Set<Integer> getPermutations(int n)
	{
		Set<Integer> perms = new TreeSet<Integer>();
		char[] digits = String.valueOf(n).toCharArray();
		
		for(int firstPos = 1; firstPos < digits.length; firstPos++)
		{
			String toBuild = "";
			for(int k = 0; k < digits.length; k++)
				toBuild += digits[(firstPos + k) % digits.length];
			perms.add(Integer.parseInt(toBuild));
		}
		return perms;
	}
	

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

package codejam;

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

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int test=args.length/2;
      

        int len=0,i,m,tem,val=0,l=0,count=0,count1=0,j=1,k;
        char arr[];
        String sec;
        int secnd;
        char temp;
        int f=1;
        int[] array=new int[500];
        int[][] array1=new int[1000][2];
        while(test!=0)
        {
            int start=Integer.parseInt(args[f]);
            int end=Integer.parseInt(args[f+1]);
            while(start<end)
            {
            String st=String.valueOf(start);
            len=st.length();
            char arr1[]=new char[len];
            if(len>1)
            {
            for(i=0;i<len;i++)
            {
                arr=st.toCharArray();

                temp=arr[len-1];
                for(k=1;k<len;k++)
                    arr1[k]=arr[k-1];
                arr1[0]=temp;
                st=String.valueOf(arr1);
                val=Integer.parseInt(st);
                if(val<=end && val>start)
                {
                    array1[l][0]=start;
                    array1[l][1]=Integer.parseInt(st);
                    l++;
                    count1++;
                }

            }
            }
            start++;
            }
            for(i=0;i<l;i++)
            {
                for(k=i+1;k<l;k++)
                {
                    if(array1[k][0]==array1[i][0] && array1[k][1]==array1[i][1])
                    {
                        if(count1>0)
                     count1--;
                    }
                }
            }


            System.out.println("Case #"+j+ ": "+count1);
            j++;
            test--;
            count1=0;
            f=f+2;
            l=0;
        }
    }

}
