import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		int casos=1, a, b, n, m, cont;
		while(t!=0){
			a=sc.nextInt();
			b=sc.nextInt();
			if(a>b){
				int aux=a;
				a=b;
				b=aux;
			}
			System.out.printf("Case #%d: ",casos++);
			if(a==b){
				System.out.printf("%d\n",0);
			}else{
				cont=0;
				for(n=a;n<b;n++){					
					for(m=n+1;m<=b;m++){					
						if(isRecycled(n,m)) cont++;
					}
				}
				System.out.printf("%d\n",cont);
			}
			t--;
		}		
	}
	public static boolean isRecycled(int n1, int n2){
		String s1, s2, aux;
		s1 =  String.valueOf( n1 );
		s2 =  String.valueOf( n2 );		
		boolean r = false;		
		for(int i=0;i<s1.length();i++){
			aux="";
			aux=s1.substring(i,s1.length())+s1.substring(0,i);
//			System.out.println(aux);
			if(aux.equals(s2)){
				r=true;
				break;
			}
		}		
		return r;
	}
}


import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

/**
 *
 * @author leonardo
 */
public class RecyclingNumbers {
  
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long inputSize = Integer.parseInt(scanner.nextLine());
        
        for (long i = 1; i <= inputSize; i++) {
            String[] input = scanner.nextLine().split(" ") ;
            
            /* No solution exists. */
            if (input.length == 1)
                continue ;
            
            long a = Long.parseLong(input[0]) ;
            long b = Long.parseLong(input[1]) ;
            System.out.println("Case #" + i + ": " + countRecyclablePairs(a, b)) ;
        }        
    }
    
    private static long countRecyclablePairs(long a, long b) {
        if (a == b)
            return 0 ;        
                
        long count = 0 ;
        for(long n = a; n <= b; n++) {                   
                                   
            LinkedList<Long> digits = toLinkedList(n) ;
            Set<Long> counted = new HashSet<Long>() ;
            
            for(long i = 0; i < digits.size(); i++) {                                
                digits.addFirst(digits.removeLast()) ;
                long m = toNumber(digits) ;
                
                if (! counted.contains(m) && n < m && m <= b) {
                    counted.add(m) ;
                    count++ ;
                }
            }            
        }
        return count ;
    }    
    
    private static LinkedList<Long> toLinkedList(long number) {
        LinkedList<Long> digits = new LinkedList<Long>() ;                
        long remainer = 0 ;
        
        while(number >= 10) {
            remainer = number % 10 ;
            digits.addFirst(remainer);
            number = number / 10 ;
        }
        
        digits.addFirst(number) ;        
        return digits ;
    }    
    
    private static long toNumber(LinkedList<Long> digits) {
        long number = 0 ;
        long expoent = digits.size() - 1 ;
        
        for(long d : digits) {
            number += d * Math.pow(10, expoent) ;
            expoent-- ;
        }
        
        return number ;
    }
}
