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

public class RecycledNumbers
{
   public static void main(String[] args)
   {
      java.util.Scanner console = new java.util.Scanner(System.in);

      int T = 0;
      int A = 0, B = 0;

      int numRecycledNumbers = 0;


      T = console.nextInt();
      console.nextLine();

      for (int i = 0; i < T; i++)
      {
         A = console.nextInt();
         B = console.nextInt();
         console.nextLine();

         // do stuff
         numRecycledNumbers = findRecycledNumbers(A, B);

         System.out.println("Case #" + (i + 1) + ": " + numRecycledNumbers);
      }      


      return;
   }


   private static int findRecycledNumbers(int A, int B)
   {
      int n = B;
      int magnitude= 0;
      int pairs = 0;
      boolean alreadySubtractedOne = false;

      String str_m = String.valueOf(A);
      String str_n = String.valueOf(B);

      String firstHalf = "";
      String secondHalf = "";

      // m = x.y * 10^magnitude
      // magnitude 1 less then number of digits
      magnitude = str_n.length() - 1; 


      // halfPower is used to retrieve the first half of m.
      int halfPower = 1;
      for (int i = 0; i < (magnitude + 1) / 2; i++)
         halfPower *= 10;


      for (int m = A; m <= B; m++)
      {
         str_m = String.valueOf(m);

         
         for (int j = magnitude ; j > 0; j--)
         {
            // Substring goes from start to end - 1, hence need to add 1
            // as 'magnitude' already has 1 subtracted from it.
            str_n = str_m.substring(j, magnitude + 1) + str_m.substring(0, j);


            n = Integer.parseInt(str_n);

            if ((n > m) && (n <= B))
            {
               // If m is of even length and first half matches second half
               // two duplicate entries can be generated, so subtract 1 from count
               // ie. xyz|xyZ => Zxyz|xy or z|xyZxy
               if (!alreadySubtractedOne &&
                  (((m % halfPower) * halfPower) == (m - (m % halfPower))))
               {
                  alreadySubtractedOne = true;
                  pairs--;
               }
               
               pairs++;
            }
         }
         
      }

      return pairs;
   }

}
