import java.io.*;
import java.util.*;

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}

import java.util.LinkedList;
import java.util.Scanner;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;


/**
 *Recycled Numbers
 */

/**
 * @author Avengee
 */

public class Demo {

	public static void main(String[] args) throws IOException {
		//Reading and Writing Files
		Scanner scan = new Scanner(new File("C-large.in"));
		FileWriter writer = new FileWriter("C-large-output.txt");
		PrintWriter pw = new PrintWriter(writer);

		//variable declaration
		int T,A,B;
	
		//code
		T = scan.nextInt();
		for (int i=1;i<=T;i++) 
		{
			A = scan.nextInt();
			B = scan.nextInt();
			int y=0;
			
			int num=String.valueOf(A).length();//number of digits
			int nl=A;
			
			while(nl<=B)
			{
				int n=nl;
				LinkedList<Integer> s=new LinkedList<Integer>();
			for(int j=1;j<num;j++)
			{
				int m,mult=1;;
				
				int k=n%10;
				n/=10;
				for(int l=1;l<num;l++)
					mult*=10;
				m=(k*mult)+n;
				int index=s.indexOf(m);
				if(m>nl && m<=B)
					{
					if(index>=0);
					else{y++;
					s.add(m);}
					}
				n=m;
			}
			
			nl++;
			
			}
			
			System.out.println("Case #"+i+": "+y);
			pw.println("Case #"+i+": "+y);
			
		}
	
		scan.close();
		writer.close();	
	}
	

}


