/*
 * 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.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;


public class RN
{
	public static Set<Pair<Integer, Integer>> RNPair = new HashSet<Pair<Integer, Integer>>();
	public static class Pair<L,R> {

		  private final L left;
		  private final R right;

		  public Pair(L left, R right) {
		    this.left = left;
		    this.right = right;
		  }

		  public L getLeft() { return left; }
		  public R getRight() { return right; }

		  @Override
		  public int hashCode() { return left.hashCode() ^ right.hashCode(); }

		  @Override
		  public boolean equals(Object o) {
		    if (o == null) return false;
		    if (!(o instanceof Pair)) return false;
		    Pair pairo = (Pair) o;
		    return this.left.equals(pairo.getLeft()) &&
		           this.right.equals(pairo.getRight());
		  }

		}
	public static void main(String[] args)
	{

		Scanner scnr = new Scanner(System.in);
		int T = scnr.nextInt();
		for (int t = 1; t <= T; t++)
		{
			RNPair.removeAll(RNPair);
			Integer first = scnr.nextInt();
			Integer last = scnr.nextInt();

			int ans = 0;
			for (int i = first; i < last; i++)
			{
				ans += check(first, last, i);
			}
			//ans /= 2;

			System.out.println("Case #" + t + ": " +RNPair.size());

		}

	}

	public static int check(Integer start, Integer end, Integer num)
	{
		String numStr = num.toString();
		int l = numStr.length();
		int count = 0;
		for (int i = 0; i < l - 1; i++)
		{
			String rotStr = numStr.substring(l - i - 1) + numStr.substring(0, l - i - 1);

			int rotStrNum = Integer.parseInt(rotStr);
			if (rotStrNum < start || rotStrNum > end)
				continue;
			
			if (rotStrNum <= num)
				continue;

			if (num.toString().length() != Integer.toString(rotStrNum).length())
				continue;
			

			if ((start <= num) && (num < rotStrNum) && (rotStrNum <= end))
			{
				count++;
				Pair<Integer, Integer> p = new Pair<Integer, Integer>(num, rotStrNum);
				RNPair.add(p);
				//System.out.println(num + " " + rotStrNum);
			}

		}
		return count;

	}

}
