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;
	}
}

/*
 *	3rd task of this years google Code Jam, lets see what I can do 
 */

//Import of java classes and packages
import java.util.Locale;
import java.util.Scanner;

//Body class
public class RecycledNumbers {

	//main class start
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		sc.useLocale(Locale.US);
		
		int recycledCount = 0;
		
		int testCount = sc.nextInt();
		
		//This cycle will run for every test (why so obvious?)
		for(int i = 0; i < testCount; i++){
			int first = sc.nextInt();
			int second = sc.nextInt();
			recycledCount = 0;	
			
			for(int j = first; j <= second; j++){
				if(j < 10)
					continue;
				
				String numberString = new String("" + j);
				for(int k = 1; k < numberString.length(); k++){
					String newNumber = new String(numberString.substring(k, numberString.length()) + numberString.substring(0,k));
					//System.out.println(newNumber);
					int number = Integer.parseInt(newNumber);
					if((number > j) && (number <= second))
						recycledCount++;
				}
			}
			
			System.out.println("Case #" + (i+1) + ": " + recycledCount);			
		}
		
	}
	//main class end
}
