/*
 * 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.io.*;
import java.util.*;
//import java.math.*;

public class c {

	public static void main(String[] args) throws IOException
	{
		Scanner qwe = new Scanner(new File("c.in"));
		BufferedWriter out = new BufferedWriter(new FileWriter("c.out"));
		int t = qwe.nextInt();
		for(int i = 1; i <= t; i++)
		{
			int a = qwe.nextInt();
			int b = qwe.nextInt();
			int[] been = new int[2000001];
			long count = 0;
			
			for(Integer j =a; j <= b; j++)
			{
				//if(been[j] > 1 && i == 4)
					//System.out.println(i + " " +j +  " " + been[j]);
				if(been[j] > 0)
					count += been[j];
				String s = j.toString();
				ArrayList<String> tocheck = new ArrayList<String>();
				for(int k = 1; k < s.length(); k++)
				{
					String torec = s.substring(k);
					String end = s.substring(0,k);
					String combin = torec+end;
					if(!tocheck.contains(combin))
						been[Integer.parseInt(combin)] += 1;
					tocheck.add(combin);
				}
				
			}
			
			out.write("Case #" + i + ": " + count +  "\n");
		}
		out.close();
	}
}

