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

import java.io.FileNotFoundException;
import java.util.Scanner;
import java.io.File;

/**
 *
 * @author kutub
 */
public class rn {
    public static void main(String args[]) throws FileNotFoundException
    {
        File f=new File("C:/Users/kutub/Documents/NetBeansProjects/JavaApplication1/src/javaapplication1/input2.txt");
        Scanner s=new Scanner(f);
        int n=0,a=0,b=0,count=0;
        while(s.hasNext())
        {
            n=s.nextInt();
            
            for(int i=1;i<=n;i++)
            {
                s.nextLine();
                a=s.nextInt();
                b=s.nextInt();
                count=0;
                
                for(int j=a;j<=b;j++)
                {
                    //System.out.println(j);
                    if(j>1000)
                    {
                        
                        int k=j%10;
                        int l=j/10;
                        int m=l%10;
                        int no=l/10;
                        int ko=no%10;
                        int lo=no/10;
                                
                                
                        int mo=k*1000+l;
                        
                        if(mo>j && mo<=b && mo>a)
                        {
                            //System.out.println("mo: "+mo);
                            count++;
                        }
                        
                        mo=m*1000+k*100+no;
                        if(mo>j && mo<=b && mo>a)
                        {
                            //System.out.println("mo: "+mo);
                            count++;
                        }
                        
                        mo=ko*1000+m*100+k*10+lo;
                        if(mo>j && mo<=b && mo>a)
                        {
                            //System.out.println("mo: "+mo);
                            count++;
                        }
                        
                       
                        
                    }
                    
                    if(j<=1000 && j>100)
                    {
                        
                        int k=j%10;
                        int l=j/10;
                        int m=l%10;
                        int no=l/10;
                        
                        int mo=k*100+l;
                        
                        if(mo>j && mo<=b && mo>a)
                        {
                            //System.out.println("j: "+j+"  mo: "+mo);
                            
                            count++;
                        }
                        
                        mo=m*100+k*10+no;
                        if(mo>j && mo<=b && mo>a)
                        {
                            //System.out.println("j: "+j+"  mo: "+mo);
                            count++;
                        }
                    }
                    else if(j<=100 && j>=10 )
                    {
                        
                        int k=j%10;
                        int l=j/10;
                        int m=(k*10)+l;
                        
                        
                        if(m<=b && m>a && m>j)
                        {
                            
                            //System.out.println("j: "+j+"  mo: "+m);
                            count++;
                        }
                            
                    }
                }
                System.out.print("Case #"+i+": ");
                System.out.println(count);
            }
        }
    }
}
