package qual;

import java.util.Scanner;

public class RecycledNumbers {

	public static void main(String[] args) {
		new RecycledNumbers().run();

	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int result = solve(A, B);
			System.out.printf("Case #%d: %d\n", t + 1, result);
		}
	}

	public int solve(int A, int B) {
		int result = 0;
		for (int i = A; i <= B; i++) {
			int dig = (int) Math.log10(A/*same as B*/) + 1;
			int aa = i;
			for (int d = 0; d < dig - 1; d++) {
				aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
				if (i == aa) {
					break;
				}
				if (i < aa && aa <= B) {
//					System.out.printf("(%d, %d) ", i, aa);
					result++;
				}
			}
		}
		return result;
	}

}

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

/**
 *
 * @author Joel
 */
import java.io.*;
public class RecycledNumbers
{
    public static void main(String[] args)
    {
        try
        {
            FileWriter output = new FileWriter("C:\\Users\\Joel\\Documents\\CSCI 221\\Netbeans Projects\\Google CodeJam\\src\\C-small-attempt2.out");
            BufferedWriter out = new BufferedWriter(output);
            FileReader reader = new FileReader("C:\\Users\\Joel\\Documents\\CSCI 221\\Netbeans Projects\\Google CodeJam\\src\\C-small-attempt2.in");
            BufferedReader in = new BufferedReader(reader);
            int p = Integer.parseInt(in.readLine());
            StringBuilder test;
            int count = 0;
            for (int i = 0; i < p; i++)
            {
                String nums = in.readLine();
                int m = Integer.parseInt(nums.substring((nums.indexOf(" ")) + 1));
                int n = Integer.parseInt(nums.substring(0, nums.indexOf(" ")));
                for (int j = n; j < (m+1); j++)
                {
                    test = new StringBuilder(Integer.toString(j));
                    int k;
                    do
                    {
                        char move = test.charAt(test.length() - 1);
                        test.insert(0, move);
                        test.deleteCharAt(test.length() - 1);
                        k = Integer.parseInt(test.toString());
                        if (k > j && k < (m + 1) && k != j)
                            count++;
                    }
                    while(k != j);
                }
                out.write("Case #" + (i + 1) + ": " + count + "\n");
                count = 0;
            }
            out.close();
        }
        catch (IOException e)
        {
            
        }
    }
}
