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

/**
 *
 * @author krishna
 */
public class Recycled {
   

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

    public static void Program() {
        Scanner inp = new Scanner(System.in);
        String line;
        String nor[];
        int num1, num2;
        int test = Integer.parseInt(inp.nextLine());
        int num = 1;
        while (num <= test) {
            line = inp.nextLine();
            nor = line.split(" ");
            num1 = Integer.parseInt(nor[0]);
            num2 = Integer.parseInt(nor[1]);
            System.out.println("Case #"+num+": "+CountNum(num1, num2));
            num++;
        }


    }

    public static int CountNum(int num1, int num2) {
        int count = 0;
        int goMax[]={9,99,999,9999,99999,999999};
        int goMin[]={0,10,100,1000,10000,100000};
        int length;
        for (int x = num1; (x < num2) && !leadingZeros(x); x++) {
            {
                 length=Integer.valueOf(x).toString().length();
                 count +=found(x,Math.max(num1,(int)goMin[length-1]),(int)Math.min(num2,goMax[length-1]));
                     
            }
        }

        return count;
    }

    private static int found(int num, int min, int max) {
     
        int part1;
        int part2;
        int zero=10;
        String join;
        int rem;
        int count=0;
          while(num/zero !=0)
          {
              rem=num%zero;
           
              part1=rem;
              part2=num/zero;
              
                
              join=part1+""+part2;
              zero =zero*10;
             if(Integer.parseInt(join)>=min && Integer.parseInt(join)<=max && Integer.parseInt(join) > num  && checkLength(num,join)  ){
                  
                  count++;
              }
             
              if(alternate(join,max))
                  count--;
          }
        return count;
    }
 public static boolean leadingZeros(int num)
{
  String str=num+"";
  if(str.charAt(0)=='0')
      return true;
  else
      return false;
      
}
 public static boolean checkLength(int num1,String str2)
 {
     String str1=num1+"";
     if(str1.length() == str2.length())
         return true;
     else
         return false;
 }
 public static boolean alternate(String str,int max)
 {
     String str2=str.substring(1);
     str2=str2+str.charAt(0);
     if(str==str2)
     {
         return true;
     }
     else
         return false;
 }
}

