import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

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

import java.io.*;
import java.util.Scanner;
import javax.swing.JOptionPane;

/**
 *
 * @author nick
 */
public class ProbC {

    public static int numLines = 0;
    public static String[] dataLine;
    public static String[] outLine;

    public static void main(String[] args) throws UnsupportedEncodingException, IOException {

        // input

        //JOptionPane.showMessageDialog(null, "This program provides a decrypter for Google's third CodeJam question: Recycled Numbers.");

        getInput();

        decode();

        writeOutput();

    }

    private static void getInput() throws FileNotFoundException {
        Scanner scanner = new Scanner(new FileInputStream("input.txt"));
        try {
            numLines = Integer.parseInt(scanner.nextLine());
            dataLine = new String[numLines];
            outLine = new String[numLines];
            for (int i = 0; i < numLines; i++) {
                dataLine[i] = scanner.nextLine();
            }
        } finally {
            scanner.close();
        }
    }

    private static void writeOutput() throws UnsupportedEncodingException, FileNotFoundException, IOException {
        Writer out = new OutputStreamWriter(new FileOutputStream("output.txt"));
        try {
            String outText = "";
            for (int i = 0; i < numLines; i++) {
                outText = outText + outLine[i] + "\n";
            }
            out.write(outText);
        } finally {
            out.close();
        }
    }

    private static void decode() {

        for (int i = 0; i < numLines; i++) {


            Scanner sc = new Scanner(dataLine[i]);
            String numOneString = sc.next();
            String numTwoString = sc.next();
            sc.close();
            int numOneInt = Integer.parseInt(numOneString);
            int numTwoInt = Integer.parseInt(numTwoString);
            int length = numOneString.length();
            int setLength = numTwoInt - numOneInt;
            String tempString = "";
            int tempInt = 0;

            int answer = 0;

            int[] answers = new int[numTwoInt];


            tempInt = numOneInt;


            for (int ii = 0; ii < setLength; ii++) {

                tempString = "" + tempInt;


                for (int iii = 0; iii < length; iii++) {


                    tempString = tempString.substring(1) + tempString.charAt(0);


                    if (Integer.parseInt(tempString) >= tempInt & Integer.parseInt(tempString) <= numTwoInt) {
                        if (Integer.parseInt(tempString) != tempInt) {
                            
                            answer++;

                        }
                    }
                }

                tempInt++;
            }

            outLine[i] = "Case #" + (i + 1) + ": " + answer;

        }

    }
}
