import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

	}
	
	
}
import java.util.*;
import java.io.*;
public class Tester
{
    public static void main(String[]args) throws IOException
    {
        Scanner sc = new Scanner(new File("C-small-attempt1.in"));
        int intNum = sc.nextInt();
        sc.nextLine();
                String[] first = new String[intNum];
        String[] second =new String[intNum];
        for(int i =0;i<intNum;i++)
        {
            first[i] =sc.next();
            second[i]=sc.next();
        }

        int recycle = 0;
        //Loop through each set of numbers
        for(int i = 0;i<intNum;i++)
        {
            //List of recycled numbers
                    ArrayList recycled = new ArrayList();
            recycle = 0;
            //Get the first and second number.
            int firstNum = Integer.parseInt(first[i]);
            int secondNum = Integer.parseInt(second[i]);
            //LOOP THROUGH THE FIRST TO SECOND NUM
            for(int j = firstNum;j<secondNum+1;j++)
            {
                //GET THE CURRENT NUMBER
                String temp = Integer.toString(j);
                //LOOP THROUGH EACH DIGIT
                for(int k = 0;k<temp.length();k++)
                {
                    //GET THE SUBSTRING OF IT AND APPEND IT TO THE BEGINNING
                    String append = temp.substring(k+1);
                    append +=temp.substring(0,k+1);
                    //CHECK FOR LEADING 0'S
                    if(append.charAt(0)!='0')
                    {
                        //GET THE ACTUAL NUMERIC NUMBER
                    int appendNum = Integer.parseInt(append);
                    //Switched number in the range
                    if(appendNum<=secondNum)
                    {
                        //Check if it is lower than tested numbers
                        if(appendNum>j)
                        {
                            //If it is  greater than the first number

                            recycle++;recycled.add(append);
                        }
                    }
                }
            }
            }
            System.out.println("Case #" + (i+1) + ": " + recycle);
        }
    }
}
