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

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
/*
 * 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
    }
}
