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

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

/**
 *
 * @author imgps
 */
public class C {
    public static void main(String args[]) throws Exception{
        int A,B;
        int ctr = 0;
        int testCases;
        
        Scanner sc = new Scanner(new FileInputStream("C-small-attempt0.in "));
        testCases = sc.nextInt();
        int input[][] = new int[testCases][2];
        for(int i=0;i<testCases;i++)
        {
          //  System.out.print("Enter input A B: ");
            input[i][0] = sc.nextInt();
            input[i][1] = sc.nextInt();
            
        }
  

for(int k=0;k<testCases;k++){
      ctr = 0;
      A = input[k][0];
      B = input[k][1];
        for(int i = A;i<=B;i++){
            int num = i;
            int nMul = 1;
            int mul = 1; 
            int tnum = num/10;
            while(tnum > 0){
                mul = mul *10;
                tnum= tnum/10;
            }
            tnum = num;
            int n = 0;
            while(tnum > 0 && mul >= 10){
                nMul = nMul * 10;
                n = (num % nMul) * mul + (num / nMul);
                mul = mul / 10;
                tnum = tnum / 10;
                for(int m=num;m<=B;m++){
                    
                    if(n == m && m > num){
                        ctr++;
                    }
                }
                
                
                
         
            }
        }
        System.out.println("Case #"+(k+1)+": "+ctr);
        
    }
    }
}

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;




public class RecycleNumbers 
{
	
	@SuppressWarnings("deprecation")
	private static void solveProblem() 
	{
		// Stream to read file
		FileInputStream fin;
		// Stream to write file
		FileOutputStream fout;
	
		try
		{
		    // Open an input stream
		    // fin = new FileInputStream ("B-large.in");
			fin = new FileInputStream ("input.txt");
		    // Open an output stream
		    fout = new FileOutputStream ("output.txt");
		    // reader
		    DataInputStream reader = new DataInputStream(fin);
		    // writer
		    PrintStream writer = new PrintStream(fout);
		    
		    int numCases = Integer.parseInt(reader.readLine());
		    
		    String line = "";
		    for (int i = 1; i <= numCases; i++) 
		    {		    	
		    	line = "Case #" + i + ": " + solveCase(reader);
		    	writer.println(line);
		    	System.out.println(line);
			}		    
	
		    // Close our input stream
		    fin.close();
		    // Close our output stream
		    fout.close();
		}
		// Catches any error conditions
		catch (IOException e)
		{
			System.err.println ("Unable to read from file");
			System.exit(-1);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@SuppressWarnings("deprecation")
	public static String solveCase(DataInputStream reader) throws Exception, IOException
	{
		return getNumRecyclers(reader.readLine().split(" "));
	}
	
	private static String getNumRecyclers(String[] values) 
	{
		int A = Integer.parseInt(values[0]);
		int B = Integer.parseInt(values[1]);
		
		int n, m, numRescyclers = 0;
		String numS = "";
		for (n = A; n <= B; n++) 
		{
			numS = n + "";
			for (int length= numS.length(), j = 0; j < length; j++) 
			{
				// A <= n < m <= B.
				m = Integer.parseInt(numS);
				if ( A <= n && n < m && m <= B ) numRescyclers++;
//				if ( A <= n && n < m && m <= B ) {
//					numRescyclers++;
//					System.out.println("("+n+","+m+")");
//				}
				numS = numS.charAt(length-1) + numS.substring(0, length-1);
			}
		}
		
		return numRescyclers + "";
	}

	public static void main(String[] args) 
	{
		solveProblem();		
	}
}
