/*
 * 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.*;

public class recycle
{

	public static StringTokenizer st;

	public static void main(String[] args)
	{
		try
		{
			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("C-small-attempt0.in")));
			PrintWriter pw = new PrintWriter(new FileWriter("output.out"));
			int T = Integer.parseInt(br.readLine());
			int t = 1;
			while (t <= T)
			{
				st = new StringTokenizer(br.readLine(), " ", false);
				int A = Integer.parseInt(st.nextToken());
				int B = Integer.parseInt(st.nextToken());
				boolean[] arr = new boolean[B-A+1];
				int order = 0;
				for (int i = A; i <= B; i++) if (!arr[i-A])
					order += cycleOrder(i, A, B, arr);
				pw.println("Case #"+t+": "+order);
				t++;
			}
			pw.flush();
			pw.close();
			br.close();
		}
		catch (IOException ie)
		{
			ie.printStackTrace();
		}
	}
	
	public static int cycleOrder(int i, int A, int B, boolean[] arr)
	{
		arr[i-A] = true;
		String s = i+"";
		int order = 1;
		for (int j = 1; j < s.length(); j++)
		{
			String s2 = s.substring(j,s.length())+s.substring(0,j);
			if (s2.equals(s)) break;
			if (!s2.startsWith("0"))
			{
				int j2 = Integer.parseInt(s2);
				if (j2 >= A && j2 <= B)
				{
					order++;
					arr[j2-A] = true;
				}
			}
		}
		return order*(order-1)/2;
	}

}