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

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

/**
 *
 * @author AEK
 */
public class Problem_C_small {
    public static void main(String[] args)throws IOException {

        
        BufferedReader reader = new BufferedReader(new FileReader("C-large.in"));
        FileWriter writer = new FileWriter("C-large-output0");
        int amount_of_test_case = Integer.parseInt(reader.readLine());
        
        for(int test_case = 1;test_case <= amount_of_test_case;test_case++) {
            Scanner parser = new Scanner(reader.readLine());
            int A = Integer.parseInt(parser.next());
            int B = Integer.parseInt(parser.next());

            int count = 0;

            for(Integer n = A;n < B;n++) {

                String outer = n.toString();
                int length = outer.length();
                for(int begin = 0;begin < outer.length();begin++) {
                    String substring = outer.substring(begin) + outer;
                    substring = substring.substring(0, length);
                    Integer m = Integer.parseInt(substring);
                    //Integer m = Integer.parseInt(outer.substring(begin) + outer.substring(0, begin));

                    if(A <= n && n < m && m <= B) {
                        count+=1;
                    }
                }// end inner loop
            }// end outer loop

            //System.out.println(count);
            writer.write("Case #" + test_case + ": " + count + "\n");
        }
        
        reader.close();
        writer.close();
        
    }// end function
    
}
