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));
			
		}
		
		
		

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

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

/**
 *
 * @author Stefanos
 */
public class RecycledNumbers {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        String input, temp;
        String output = "";
        int left, right;
        int i = 0, bingo;
        int cases, size;
                
        try {  
            FileReader fr = new FileReader(new File("C-small-attempt0.in"));  
            BufferedReader br = new BufferedReader(fr);
            
            FileWriter fstream = new FileWriter("C-small-attempt0.out");
            BufferedWriter out = new BufferedWriter(fstream);

            cases = Integer.parseInt(br.readLine());
            i = 0;

            while(i < cases) {
                input = br.readLine();
                output += "Case #"+(++i)+": "; 
                String[] split = input.split(" ");
                bingo = 0;
                
                if (split[0].length()>1) {
                    left = Integer.parseInt(split[0]);
                    right = Integer.parseInt(split[1]);
                    
                    for (int j=left; j<right; j++) {
                        for (int k=j+1; k<=right; k++) {
                            String num = Integer.toString(k);
                            size = num.length();
                        
                            for(int m=0; m<size-1; m++) {
                            
                                int concat = Integer.parseInt(num.substring(m+1, size)+num.substring(0, m+1));
                                
                                if(j == concat) { bingo++; break;}                     
                            }                       
                        }
                    }
                    
                    
                }
                out.write(output+bingo);
                output = "\n";
            }

            out.close();
            br.close();
            
        }catch (Exception e) { System.err.println("Error: " + e.getMessage()); }
    }
}
