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

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package googlejam;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

/**
 *
 * @author AEK
 */
public class Problem_C_small {
    public static void main(String[] args)throws IOException {

        
        BufferedReader reader = new BufferedReader(new FileReader("C-large.in"));
        FileWriter writer = new FileWriter("C-large-output0");
        int amount_of_test_case = Integer.parseInt(reader.readLine());
        
        for(int test_case = 1;test_case <= amount_of_test_case;test_case++) {
            Scanner parser = new Scanner(reader.readLine());
            int A = Integer.parseInt(parser.next());
            int B = Integer.parseInt(parser.next());

            int count = 0;

            for(Integer n = A;n < B;n++) {

                String outer = n.toString();
                int length = outer.length();
                for(int begin = 0;begin < outer.length();begin++) {
                    String substring = outer.substring(begin) + outer;
                    substring = substring.substring(0, length);
                    Integer m = Integer.parseInt(substring);
                    //Integer m = Integer.parseInt(outer.substring(begin) + outer.substring(0, begin));

                    if(A <= n && n < m && m <= B) {
                        count+=1;
                    }
                }// end inner loop
            }// end outer loop

            //System.out.println(count);
            writer.write("Case #" + test_case + ": " + count + "\n");
        }
        
        reader.close();
        writer.close();
        
    }// end function
    
}
