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.io.*;

public class Recycled{
public static void main(String args[])
{
try{
File myFile = new File("C-small-attempt0.in");
FileReader fileReader = new FileReader(myFile);

BufferedReader reader = new BufferedReader(fileReader);
FileWriter fileWriter = new FileWriter("C-small-attempt0.out");
BufferedWriter writer = new BufferedWriter(fileWriter);
String line = null;
line = reader.readLine();
int numLines = Integer.parseInt(line);
//writer.write("hello");
for(int i=0;i<numLines;i++)
{
int recyclecount = 0;
line = reader.readLine();
String AB[] = line.split(" ");

int a = Integer.parseInt(AB[0]);
int b = Integer.parseInt(AB[1]);
int length = AB[0].length();

//the initial value of n

for(int n=a;n<b;n++)
{
System.out.println("N: " + n);
//writer.write("N " + n+"\r\n");
//recycle the value by taking the last digit forward and check with the range,and then the last two digits,etc
for(int j=1;j<length;j++){
if(length!=1){
int tail = n%(int)Math.pow(10,j);
int head = n/(int)Math.pow(10,j);
//concatenate the head and tail and form a new number
int newNumber = Integer.parseInt(tail +""+head);

if((newNumber+"").length() == length){
System.out.println(newNumber);
//writer.write("new " + newNumber+"\r\n");
//compare with the range n<m<=B

if(newNumber<=b && newNumber>n)
{
recyclecount++;
System.out.println("RC " + recyclecount);
//writer.write("RC " + recyclecount+"\r\n");

}

}
}
}
}
String out = "Case #" + (i+1) +": "+recyclecount+"\r\n";
writer.write(out);
System.out.println(out);


}
reader.close();
writer.close();

}catch(Exception ex){
ex.printStackTrace();
}
}
}