import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		int casos=1, a, b, n, m, cont;
		while(t!=0){
			a=sc.nextInt();
			b=sc.nextInt();
			if(a>b){
				int aux=a;
				a=b;
				b=aux;
			}
			System.out.printf("Case #%d: ",casos++);
			if(a==b){
				System.out.printf("%d\n",0);
			}else{
				cont=0;
				for(n=a;n<b;n++){					
					for(m=n+1;m<=b;m++){					
						if(isRecycled(n,m)) cont++;
					}
				}
				System.out.printf("%d\n",cont);
			}
			t--;
		}		
	}
	public static boolean isRecycled(int n1, int n2){
		String s1, s2, aux;
		s1 =  String.valueOf( n1 );
		s2 =  String.valueOf( n2 );		
		boolean r = false;		
		for(int i=0;i<s1.length();i++){
			aux="";
			aux=s1.substring(i,s1.length())+s1.substring(0,i);
//			System.out.println(aux);
			if(aux.equals(s2)){
				r=true;
				break;
			}
		}		
		return r;
	}
}

import java.io.*;
import java.util.*;
public class C

{
     BufferedReader read;
     BufferedWriter write;
    public static void main(String args[])
    {
        try {
            new C().init("C-small-attempt2");
        } catch (Exception ex) {
               System.out.println("error occured  "+ex);
          //  Logger.getLogger(Sample.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
     void init(String name) throws Exception
    {

        
        read=new BufferedReader(new FileReader(new File(name+".in")));
        write=new BufferedWriter(new FileWriter(new File(name+".out")));
        
        
          String x="";


            try {
                x = read.readLine();
               int n = Integer.parseInt(x);
              for(int i=0;i<n;i++)
                 {
                   x = read.readLine();
                   result(x, i);
                }
                write.flush();
                write.close();
                read.close();

               // System.out.println(a+"    "+b);
                }

             catch (Exception ex) {
                 System.out.println("error occured  "+ex);

               System.exit(0);
            }


      }
     TreeSet<Integer>tree;

void result(String x,int j) throws Exception
{
             tree=new TreeSet<Integer>();
             String ss[]=x.split(" ");
                int a=Integer.parseInt(ss[0].trim());
                int b=Integer.parseInt(ss[1].trim());
                System.out.println(a+"   "+b);
                int count=0;
                for(int i=a;i<=b;i++)
                {

                        tree.add(i);
                        count+=count(i,a,b);
                     
                   
                }
                System.out.println("Case #"+(j+1)+": "+count);
               write.write("Case #"+(j+1)+": "+count+"\n");
}

int count(int p,int a,int b)
    {
    TreeSet<Integer>t=new TreeSet<Integer>();
    
   
    String s=""+p;
    s=s.trim();
    int l=s.length();
    for(int i=1;i<l;i++)
    {
        if(s.charAt(i)=='0')continue;
        int p1=Integer.parseInt(s.substring(i)+s.substring(0, i));
        if(p!=p1&&p1<=b&&p1>=a&&!tree.contains(p1))
        {
        //    System.out.print("\t"+p+"  "+p1);
            t.add(p1);
        }
    }
    return t.size();
}

}
