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

import java.util.HashSet;

/**
 *
 * @author vandit
 */
public class RecycleNumbers {

    private HashSet<String> numbers = new HashSet<String>();
    private HashSet<String> initialTempNumbers = new HashSet<String>();
    private HashSet<String> finalTempNumbers = new HashSet<String>();

    HashSet<Pair> numberPairs = new HashSet<Pair>();


    private void findRecycledNumbers(int start, int end, int places) {


        for (int i = start; i <= end; i++) {
            String initialNumber = Integer.toString(i);
            //if (!(numbers.contains(initialNumber) || finalTempNumbers.contains(initialNumber))) {

                StringBuffer tempNumber = new StringBuffer(initialNumber);
                int len = tempNumber.length();
                int startIndexToMove = len - places;
                String tempString = tempNumber.substring(startIndexToMove);
                if ((places == 1 && tempString.equals("0")) || tempString.charAt(0) == '0') {
                    continue;
                }
                tempNumber.delete(startIndexToMove, len);
                String finalTempNumber = tempString + tempNumber.toString();

                if (! (finalTempNumber.equals(initialNumber) || Integer.parseInt(finalTempNumber) > end || Integer.parseInt(finalTempNumber) < Integer.parseInt(initialNumber))) {
                    numbers.add(initialNumber);
                    finalTempNumbers.add(finalTempNumber);
                    Pair pair = new Pair(finalTempNumber,initialNumber);
                    numberPairs.add(pair);
                }
            }

        

    }

    public HashSet<Pair> findAllRecycledNumbers(int start, int end) {
        int length = Integer.toString(start).length();
        for (int i = 1; i < length; i++) {
            findRecycledNumbers(start, end, i);
        }
        return numberPairs;
    }
}

import java.util.ArrayList;
import java.util.Scanner;

public class ProblemC {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int t = in.nextInt();
		int a = 0, b = 0, count;
		String a_str = "";
		ArrayList<String> ar = new ArrayList<String>();
		for (int i = 0; i < t; i++) {
			ar.clear();
			count = 0;
			a = in.nextInt();
			b = in.nextInt();
			a_str = Integer.toString(a);
			int a_length = a_str.length();
			if (a_length > 1) {
				for (int j = a; j < b; j++) {
					for (int k = j + 1; k <= b; k++) {
						a_str = Integer.toString(j);
						//b_str = Integer.toString(k);
						for (int h = 0; h < a_length - 1; h++) {
							a_str = a_str.charAt(a_length - 1) + a_str.substring(0, a_length - 1);
							if (Integer.parseInt(a_str) == k && !ar.contains(j + ", " + k)) {
								count++;
								ar.add(j + ", " + k);
								//System.out.println(j + ", " + k);
							}
						}
					}
				}
				System.out.println("Case #" + (i + 1) + ": " + count);
			} else {
				System.out.println("Case #" + (i + 1) + ": 0");
			}
		}
	}
}
