/*
 * 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.*;
import java.io.*;
import static java.lang.Math.*;

public class C {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("C:/Users/Farnoosh/Desktop/C-small.in"));
		FileWriter fw = new FileWriter("C:/Users/Farnoosh/Desktop/C-small.out");
		/*BufferedReader in = new BufferedReader(new FileReader("C:/Users/Farnoosh/Desktop/C-large.in"));
		FileWriter fw = new FileWriter("C:/Users/Farnoosh/Desktop/C-large.out");*/
		
		int N = new Integer(in.readLine());
		
			
		//System.out.print(N);
		 for (int cases = 1; cases <= N; cases++) {
			int count = 0;
			String[] ss = in.readLine().split(" ");
			
			int A = Integer.parseInt(ss[0]);
			int B = Integer.parseInt(ss[1]);
			
			
			for(int num = A ; num <= B ; num++){
				int num2 = 0;
				int len = (int)Math.pow(10, Integer.toString(num).length()-1);
				
				int i = 0;
				int num1 = num;
				for(i = 1; i < Integer.toString(num).length() ; i++){
					
					if(Integer.toString(num2).length() == Integer.toString(num1).length() || num2==0){
						num2 = 10 * (num1 % len) + (num1 / len);
					}
					else{
						num2 = num2 * 10;
					}
				
				    if(num2 == num)
				    	break;
					
					if (num2 <= B && num2 > num){
						count++;
					}// end of if
					num1 = num2;
				}//end of for
				

			}//end of for
					
			fw.write ("Case #" + cases + ": " + count + "\n");
		} 
		

		fw.flush();
		fw.close();
	}

}