package codejam;

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

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class GoogleReplaced {
    static BufferedWriter bw = null;

    public static void main(String[] args) throws Exception {
        try {
            Scanner sc = new Scanner(new File("C-small-attempt.in"));
            bw = new BufferedWriter(new FileWriter("output.txt"));
            long totalCases = sc.nextLong();
            for (int i = 1; i <= totalCases; i++) {
                int finalCount = 0;
                int i1 = sc.nextInt();
                int i2 = sc.nextInt();
                int tempNum1 = i1;
                for (; tempNum1 <= i2; tempNum1++) {
                    String string = String.valueOf(tempNum1);
                    List usedList = new ArrayList();
                    for (int j = 1; j < string.length(); j++) {
                        String string1 = string.substring(string.length() - j, string
                                .length());
                        String string2 = string.substring(0, string.length() - j);
                        String newString = string1 + string2;
                        int newIntValue = Integer.parseInt(newString);

                        if ((i1 <= newIntValue) && ((i2 >= newIntValue))) {
                            if (newIntValue > tempNum1) {
                                if (!usedList.contains(newIntValue)) {
                                    usedList.add(newIntValue);
                                    finalCount = finalCount + 1;
                                }
                            }
                        }
                    }
                }
                bw.append("Case #" + i + ": ");
                bw.append(String.valueOf(finalCount));
                bw.append("\n");
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            bw.flush();
            bw.close();
        }
    }
}
