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

	}
	
	
}

package grn;

import java.io.*;
import java.util.ArrayList;

/**
 *
 * @author alexho
 */
public class GRN {
    
    private static int [] result;
    private static ArrayList<String> permutation = new ArrayList<String>();
    
    
    private void readInput (String infn) throws FileNotFoundException, IOException {
        String line = null;        
        int testCases = 0;
        BufferedReader bufRdr = null;      
        String delimiter = " ";
        File file = new File(infn);
        bufRdr = new BufferedReader(new FileReader(file));            

        testCases = Integer.valueOf(bufRdr.readLine());        
        GRN.result = new int [testCases];
        for (int i=0;i<GRN.result.length;i++) {
            GRN.result[i] = 0;
        }
        
        int index=0;
                
        while ( (line = bufRdr.readLine()) != null ) {
                        
            String [] temp;            
            temp = line.split(delimiter);
//            GRN.usedperm.clear();
            this.computeMax(temp, index);            
            index++;
//            for (int i=0;i<GRN.usedperm.size();i+=2) {
//                if (i != GRN.usedperm.size()-1)
//                    System.out.println(i/2+": "+GRN.usedperm.get(i)+","+GRN.usedperm.get(i+1));
//            }
//            System.out.println();

        }
        bufRdr.close();

        
    }
    
    private void computeMax(String [] temp, int ind) {
        
        int A,B,max=0;
        A = Integer.valueOf(temp[0]);
        B = Integer.valueOf(temp[1]);
        
        for (int n=A;n<=B;n++) {
            this.findM(n, B, ind);                             
        }
        
    }

    private void reorder(String s) {
        int len = s.length();
        String ns="";
        GRN.permutation.clear();
        for (int i=1;i<len;i++) {
            ns = s.substring(i).concat(s.substring(0, i));
            if (!ns.equals("") && !GRN.permutation.contains(ns)) {
                GRN.permutation.add(ns);
            }
        }
        
    }
    
    private void findM (int n, int B, int ind) {
        
        String alphabet = String.valueOf(n);       
        this.reorder(alphabet);     
        int m;
        
        for (int i=0;i<GRN.permutation.size();i++) {
            m = Integer.valueOf(GRN.permutation.get(i));
//            if (m <= B && m > n && !GRN.usedperm.contains(alphabet) && !GRN.usedperm.contains(GRN.permutation.get(i))) {
            if (m <= B && m > n ) {
//                GRN.usedperm.add(alphabet);
//                GRN.usedperm.add(GRN.permutation.get(i));
                GRN.result[ind]++;
            }
            
        }                
        
    }
    
    private void output (String outfn) throws IOException {
        PrintWriter out = new PrintWriter(new FileWriter(outfn));
        for (int i=0;i<GRN.result.length;i++) {
            out.println("Case #"+(i+1)+": "+GRN.result[i]);

        }
        out.close();        
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        
        GRN grn = new GRN();
        String infn = args[0];
        String outfn = args[1];
        grn.readInput(infn);
//        String test = "13105";
        
//        grn.reorder(test);

        for (int i=0;i<GRN.result.length;i++) {
            System.out.println(GRN.result[i]);
        }
        
        grn.output(outfn);
                
    }
}
