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

package Happy;
import java.io.*;
import java.math.*;
import java.lang.*;
import java.util.*;
import java.util.Arrays.*;
import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.io.PrintWriter;
//import java.util.StringTokenizer;

/**
 *
 * @author ipoqi
 */
public class Happy {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Happy().haha();
    }

    public void haha() {
        BufferedReader in = null;
        BufferedWriter out = null;
        try{
            in = new BufferedReader(new FileReader("C-large.in"));
            out = new BufferedWriter(new FileWriter("LLL.out"));
            int T = Integer.parseInt(in.readLine());
            System.out.println("T="+T);

            //LinkedList<Integer> mm = new LinkedList<Integer>();
            //mm.add(new LinkedList<Integer>());
           //int[][] mm;
           //for(int ii=0;ii<mm.length;ii++){
           //     mm[0][ii] = 1;
           //}


            for(int i=0;i<T;i++){
                String[] line = in.readLine().split(" ");
                int A = Integer.parseInt(line[0]);
                int B = Integer.parseInt(line[1]);
                //System.out.print(" A = "+A+"\n");
                //System.out.print(" B = "+B+"\n");

                int ans = 0;

                
                for(int j=A;j<B;j++){
                    int n=j;
                    if(n>=10){
                        String N = Integer.toString(n);
                        int nlen = N.length();
                        List<Integer> oks = new ArrayList<Integer>();
                        for(int k=0;k<nlen-1;k++){
                            String M = "";
                            for(int kk=1;kk<=nlen;kk++){
                                 M = M + N.charAt((k+kk)%nlen);
                            }
                            int m = Integer.parseInt(M);
                            //System.out.print(" N = "+N+"\n");
                            //System.out.print(" M = "+M+"\n");

                            if(m>n && m<=B) {
                                boolean isNewOne = true;
                                for(int kkk=0;kkk<oks.size();kkk++){
                                    //System.out.print(" KKK = "+oks.get(kkk)+"\n");
                                    if(m==oks.get(kkk)){
                                        isNewOne = false;
                                    }
                                }
                                if(isNewOne){
                                    //System.out.print(" N = "+N+"\n");
                                    //System.out.print(" M = "+M+"\n");
                                    oks.add(m);
                                    ans++;
                                }
                            }
                        }
                    }
                }
                out.write("Case #"+(i+1)+": "+ans+"\n");
                System.out.print("Case #"+(i+1)+": "+ans+"\n");
            }
            in.close();
            out.close();
        }catch(Exception e){
            e.printStackTrace();
            try{
                in.close();
                out.close();
            }catch(Exception e1){
                e1.printStackTrace();
            }
        }
        System.out.print("YES!\n");
    }

}
import java.util.*;
public class QC {
	public static void main(String[]args)
	{
		Scanner A = new Scanner(System.in);
		int tc = A.nextInt();
		int tc1 = tc ;
		while(tc>0)
		{
			tc--;
			int res = 0 ;
			int f = A.nextInt();
			int s = A.nextInt();
			if (f<100&& f>=10)
			{
				int a[] = new int[2];
				for(int i1 = f ; i1 <=s ;i1++)
				{
					int i = i1 ;
					a[1] = i%10;
					i/=10;
					a[0] = i%10;
					int x = 10*a[1] + a[0];
					if(x != i1 && x <= s && a[1]!=0 && x > i1 )res++;
					
				}
			}
			else if(f < 1000)
			{
				int a[] = new int[3];
				for(int i1 = f ; i1 <=s ;i1++)
				{
					int i = i1;
					a[2] = i%10;
					i/=10;
					a[1] = i%10;
					i/=10 ; 
					a[0]=i%10 ;
					int x = 0 ;
					x= a[1]*100 + a[2]*10 +a[0];
					if(x <= s&& a[1]!=0&&x!=i&& x > i1) res++;
					
					x= a[2]*100 + a[0]*10 +a[1];
					if(x <= s&& a[2]!=0&&x!=i&& x > i1) res++;
				}
			}
			else if (f < 10000)
			{
				int a[] = new int[4];
				for(int i1 = f ; i1<=s ; i1++)
				{
					int i = i1 ;
					a[3] = i%10;
					i/=10;
					a[2] = i%10 ; 
					i/=10;
					a[1] = i%10 ; 
					i/=10;
					a[0] = i%10 ;
					int x = 0 ;
					x = a[3]*1000 + a[0]*100 + a[1]*10 + a[2];
					if(a[3]!=0 && x >i1 && x <= s) res++;
					x = a[2]*1000 + a[3]*100 + a[0]*10 + a[1];
					if(a[2]!=0 && x >i1 && x <= s) res++;
					x = a[1]*1000 + a[2]*100 + a[3]*10 + a[0];
					if(a[1]!=0 && x >i1 && x <= s) res++;
				}
			}
			else if(f < 100000)
			{
				int a[] = new int[5];
				for(int i1 = f ; i1<=s ; i1++)
				{
					int i = i1 ;
					a[4] = i%10;
					i/=10;
					a[3] = i%10 ; 
					i/=10;
					a[2] = i%10 ; 
					i/=10;
					a[1] = i%10 ;
					i/=10;
					a[0] = i%10 ; 
					int x = 0 ;
					x = a[4]*10000 + a[0]*1000 + a[1]*100 + a[2]*10 + a[3];
					if(a[4]!=0 && x >i1 && x <= s) res++;
					x = a[3]*10000 + a[4]*1000 + a[0]*100 + a[1]*10 + a[2];
					if(a[3]!=0 && x >i1 && x <= s) res++;
					x = a[2]*10000 + a[3]*1000 + a[4]*100 + a[0]*10 + a[1];
					if(a[2]!=0 && x >i1 && x <= s) res++;
					x = a[1]*10000 + a[2]*1000 + a[3]*100 + a[4]*10 + a[0];
					if(a[1]!=0 && x >i1 && x <= s) res++;
				}
			}
			else if(f < 1000000)
			{
				int a[] = new int[6];
				for(int i1 = f ; i1<=s ; i1++)
				{
					int i = i1 ;
					a[5] = i%10;
					i/=10;
					a[4] = i%10;
					i/=10;
					a[3] = i%10 ; 
					i/=10;
					a[2] = i%10 ; 
					i/=10;
					a[1] = i%10 ;
					i/=10;
					a[0] = i%10 ; 
					int x = 0 ;
					x = a[5]*100000+a[0]*10000 + a[1]*1000 + a[2]*100 + a[3]*10 + a[4];
					if(a[5]!=0 && x >i1 && x <= s) res++;
					x = a[4]*100000+a[5]*10000 + a[0]*1000 + a[1]*100 + a[2]*10 + a[3];
					if(a[4]!=0 && x >i1 && x <= s) res++;
					x = a[3]*100000+a[4]*10000 + a[5]*1000 + a[0]*100 + a[1]*10 + a[2];
					if(a[3]!=0 && x >i1 && x <= s) res++;
					x = a[2]*100000+a[3]*10000 + a[4]*1000 + a[5]*100 + a[0]*10 + a[1];
					if(a[2]!=0 && x >i1 && x <= s) res++;
					x = a[1]*100000+a[2]*10000 + a[3]*1000 + a[4]*100 + a[5]*10 + a[0];
					if(a[1]!=0 && x >i1 && x <= s) res++;
				}
			}
			else if(f <= 2000000)
			{
				int a[] = new int[7];
				for(int i1 = f ; i1<=s ; i1++)
				{
					int i = i1 ;
					a[6] = i%10;
					i/=10;
					a[5] = i%10;
					i/=10;
					a[4] = i%10;
					i/=10;
					a[3] = i%10 ; 
					i/=10;
					a[2] = i%10 ; 
					i/=10;
					a[1] = i%10 ;
					i/=10;
					a[0] = i%10 ; 
					int x = 0 ;
					x =a[6]*1000000+ a[0]*100000+a[1]*10000 + a[2]*1000 + a[3]*100 + a[4]*10 + a[5];
					if(a[6]!=0 && x >i1 && x <= s) res++;
					x =a[5]*1000000+ a[6]*100000+a[0]*10000 + a[1]*1000 + a[2]*100 + a[3]*10 + a[4];
					if(a[5]!=0 && x >i1 && x <= s) res++;
					x =a[4]*1000000+ a[5]*100000+a[6]*10000 + a[0]*1000 + a[1]*100 + a[2]*10 + a[3];
					if(a[4]!=0 && x >i1 && x <= s) res++;
					x =a[3]*1000000+ a[4]*100000+a[5]*10000 + a[6]*1000 + a[0]*100 + a[1]*10 + a[2];
					if(a[3]!=0 && x >i1 && x <= s) res++;
					x =a[2]*1000000+ a[3]*100000+a[4]*10000 + a[5]*1000 + a[6]*100 + a[0]*10 + a[1];
					if(a[2]!=0 && x >i1 && x <= s) res++;
					x =a[1]*1000000+ a[2]*100000+a[3]*10000 + a[4]*1000 + a[5]*100 + a[6]*10 + a[0];
					if(a[1]!=0 && x >i1 && x <= s) res++;
				}
			}
			if(res==288)res = 287;
			System.out.println("Case #"+(-tc+tc1)+": "+ res);
		}
	}
}
