import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package actual;

import codejam.*;
import java.io.*;
import java.util.Scanner;
/**
 *
 * @author atm
 */
public class PCL {
   public static void main(String[] args) throws Exception {
       int Cases;
       int L,U;
       String words[];
       
        FileInputStream fstreamIN = new FileInputStream("F:\\codejam\\input\\C-large.in");
        FileOutputStream fstreamOUT = new FileOutputStream("F:\\codejam\\output\\C-large.out");
        
        Scanner in=new Scanner(fstreamIN);
        PrintWriter out=new PrintWriter(fstreamOUT);
        
        Cases=in.nextInt();
        
        for(int i=0;i<Cases;i++) // Cases loop
        {
            L=in.nextInt();
            U=in.nextInt();
            int ans=0;
            if(L==1000){
                ans=0;
            }else if(L<10){
                ans=0;
            }else if(L<100){
                
                for(int j=L;j<=U;j++){ 
                    if(revtwo(j)<=U){
                        if(revtwo(j)>j)
                            ans++;                        
                    }
                }
            } else {
                for(int j=L;j<=U;j++){ 
                    String num=Integer.toString(j);
                    for(int k=0;k<num.length();k++){
                        if(ndigcir(j,k)<=U){
                            if(ndigcir(j,k)>j)
                                ans++;                        
                        }
                    }                  
                    
                }               
            } 
             out.printf("Case #%d: %d\n",i+1,ans);
        }
        out.close();   
   }
   static int revtwo(int num){
       return (num%10)*10+(num/10);
   }
   static int onedigcir(int num)
   {
       int newnum;
       newnum=(num%10)*100+(num/10);
       return newnum;
   }
   static int twodigcir(int num)
   {
       int newnum;
       newnum=(num%100)*10+(num/100);
       
       return newnum;
   }
   static int ndigcir(int num,int n)
   {
       String number=Integer.toString(num);
       String right=number.substring(number.length()-n, number.length());
       String newNum=right+number.substring(0,number.length()-n);
       return Integer.parseInt(newNum);
   }
}
