
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 gcj12_qc;

import java.io.FileOutputStream;
import java.util.HashSet;
import java.util.Scanner;

/**
 *
 * @author youssefgamil
 */
public class Gcj12_qC {

    /**
     * @param args the command line arguments
     */
    public static String leading0(String txt)
    {
        while(txt.charAt(0)=='0')
            txt=txt.substring(1);
        return txt;
    }
    public static void main(String[] args) throws Exception {
        HashSet<String> hs=new HashSet<String>();
        Scanner sc=new Scanner(System.in);
        FileOutputStream out=new FileOutputStream("out.txt");
        int a,b,i,j,tc,T;
        long res=0;
        String tmp;
        T=sc.nextInt();
        for(tc=1;tc<=T;tc++)
        {
            a=sc.nextInt();
            b=sc.nextInt();
            res=0;
            for(i=a;i<=b;i++)
            {
//                if(hs.contains(i+""))
//                    continue;
                
                tmp=i+"";
                
//                hs.add(tmp);
  //              System.out.println(tmp+">");
                
                hs=new HashSet<String>();
                for(j=0;j<tmp.length();j++)
                {
                        tmp=tmp.substring(1)+tmp.charAt(0);

                        
                    if(!hs.contains(tmp))//+","+i) && !hs.contains(i+","+tmp))
                    {
                            hs.add(tmp);//+","+i);
                        if(a<=Integer.parseInt(tmp)&&Integer.parseInt(tmp)<=b && Integer.parseInt(tmp)!=i)
                        {
//                        System.out.println(i+","+tmp);
                            res++;
                        }
                    }
                }
            }
            res/=2L;
            System.out.print(("Case #"+tc+": "+res+"\n"));
            out.write(("Case #"+tc+": "+res+"\n").getBytes());
        }
        out.close();
        // TODO code application logic here
    }
}
