/*
 * 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.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author yo7
 */
public class ReceycledNumper2 {
    public static void main(String[] args) throws FileNotFoundException, IOException {
    BufferedReader f = new BufferedReader(new FileReader("C-small-attempt0.in"));
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
    Scanner sc=new Scanner(f);
    int n=sc.nextInt();
    sc.nextLine();
    int num1,num2;
    for(int Linenumper=1;Linenumper<=n;Linenumper++){
        String line=sc.nextLine();
        String[] tokens=line.split(" ");
        num1=Integer.parseInt(tokens[0]);
        num2=Integer.parseInt(tokens[1]);
        if(num1<10)
        {
            String ss="Case #"+Linenumper+": 0";
            out.println(ss);
            continue;
        }
        int count=0;
        for(int k=num1;k<num2;k++)
          for(int i=k;i<num2;i++)
          {
              String str1=k+"";
              String str2=i+1+"";
              int len=str1.length();
              for(int j=1;j<len;j++)
              {
                  String end=str1.substring(len-j,len);
                  String front=str1.substring(0,len-j);
                  String newstring=end+front;
                  if(newstring.equals(str2))
                  {
                      count++;
                      j=str1.length();
                  }
              }
          }
          String ss="Case #"+Linenumper+": "+count;
          out.println(ss);
    }
      
    out.close();                                  // close the output file
    System.exit(0);                               // don't omit this!
    }
}
