/*
 * 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.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;


public class Test {

	public static void main(String[] args){
		FileInputStream fstream = null;
		DataInputStream in = null;
		BufferedReader br = null;
		FileWriter fw = null;
		BufferedWriter out = null;
		
		try{
			  fstream = new FileInputStream(args[0]);
			  in = new DataInputStream(fstream);
			  br = new BufferedReader(new InputStreamReader(in));
			  
			  fw = new FileWriter(args[1]);
			  out = new BufferedWriter(fw);
			  
			  String strLine;
			  int i = 0;
			  int tc = 0;
			 
			  while ((strLine = br.readLine()) != null)   {
				  if(i == 0){
					 tc = Integer.parseInt(strLine);
					 i++;
					 continue;
				  }
				  if( i <= tc){
					  String[] arr = strLine.split(" ");
					  int minLimit = Integer.parseInt(arr[0]);
					  int maxLimit = Integer.parseInt(arr[1]);
					  int count = 0;
					  int len = arr[0].length();
					  if(len <= 1){
						  count = 0;
					  }else{
						  for(int j = minLimit; j <= maxLimit ; j++){
							  int num = j;
							  List ls = new ArrayList();
							  for(int k = 1; k < len ; k++ ){
								  int dp = (int)Math.pow(10, len -k);
								  int mp = (int)Math.pow(10, k);
								  int first = num / dp;
								  int last = num % dp;
								  int number = last*mp + first;
								  
								  if(num != number){
									  if(number <= maxLimit && number >= minLimit){
										  if(!ls.contains(number+"")){
											  ls.add(number+"");
											  count++;
										  }
										 
									  }
								  }
								  
							  }
						  }
					  }
					  count = count/2;
					  System.out.println("Case #"+i+": "+count);
					  out.write("Case #"+i+": "+count);
					  out.write(System.getProperty( "line.separator" ));
				  }
				  i++;
			  }
			  
			  in.close();
			  out.close();
		}catch (Exception e){
			e.printStackTrace();
			System.err.println("Error: " + e.getMessage());
		}
	}
	
	
}


