/*
 * 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.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;


public class C {

	Scanner in;
	public C()
	{
		in = new Scanner(System.in);
		int t = in.nextInt();               // number of test cases ...:)
		for(int l=1;l<=t;l++)
		{
			int n = in.nextInt();           // got n 
            
			int m = in.nextInt();           // got m
			
			int temp=0;                     // For Every data set it has to change 
			int temp2=0;
			int reverse=0;
			int reverse2=0;
			int count=0;
			
			if(n>=10 &&m<100)
			{
				for(int i=n;i<=m;i++)
				{
					temp=i;
					while( temp != 0 )
				      {
				          reverse = reverse * 10;
				          reverse = reverse +temp%10;
				          temp = temp/10;
				      }
					
					
					
					
					if((reverse>=n)&&(reverse<=m)&&(reverse!=i))
					{
						count++;
						
					}
					reverse=0;
				
				}
				
				count=count/2;
			}
			if(n>99 && m<=1000)
			{
				for(int i=n;i<=m;i++)
				{
					 temp=temp2=i;
					
				     
				     reverse = reverse +temp%10;
				     reverse2 = reverse2+temp%100;
				     temp = temp/10;
				     temp2=temp2/100;
				     reverse = (reverse * 100)+temp;      //one position replaced 
				     reverse2= (reverse2*10)+temp2;       //two position interchange
					
					 
					
					if((reverse>=n)&&(reverse<=m)&&(reverse!=i))
						
					{
						count++;
					}
					reverse=0;
					
                    if((reverse2>=n)&&(reverse2<=m)&&(reverse2!=i))
						
					{
						count++;
					}
					reverse2=0;
				
			}
				count=count/2;
		}
			System.out.printf("Case #%d: %d\n", l,count);
	}
	
	}
	public static void main(String[] args) {
		
		try
		{
			String inp="C-small-attempt0";
			System.setIn(C.class.getResourceAsStream(inp+".in"));
			System.setOut(new PrintStream(new File("outputC.out")));
			
		}
		catch(FileNotFoundException e)
		{
			e.printStackTrace();
		}
		
		new C();

	}

}
