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.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;


public class RecycledNumbers {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		
		Scanner in;
		/*in = new Scanner(new FileReader("C-small.in"));
		FileWriter output = new FileWriter("C-small.out");*/
		in = new Scanner(new FileReader("C-large.in"));
		FileWriter output = new FileWriter("C-large.out");
		
		int T = in.nextInt();

		for(int i = 1; i <= T; i++) {
			long a = in.nextInt();
			long b = in.nextInt();

			int recycle = 0;
			for(long n = a; n < b; n++) {
				StringBuffer sb = new StringBuffer(Long.toString(n));
				sb.trimToSize();
				long m = -1;
				
				for(int j = 1; j < sb.length(); j++) {
					sb.append(sb.charAt(0));
					sb.deleteCharAt(0);
					sb.trimToSize();

					if ( m != Long.parseLong(sb.toString()) ) {
						long check = m;
						m = Long.parseLong(sb.toString());

						if(m <= b && m>n) {
							//System.out.println(a + " " + n + " " + m + " " + b);
							recycle++;
						} else m = check;
					}
					
				}
			}
			
			output.write("Case #" + i + ": " + recycle + "\n");
			
		}
		
		in.close();
		output.flush();
		output.close();

	}

}
