/*
 * 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.*;
import static java.lang.Math.*;
import java.io.*;

public class C {
		
public static void main(String[] args) throws IOException {
  BufferedReader in = new BufferedReader(new FileReader("C:/Users/Disha/Desktop/codejam/C-small.in"));
  FileWriter fw = new FileWriter("C:/Users/Disha/Desktop/codejam/C-small.out");
  /*BufferedReader in = new BufferedReader(new FileReader("C:/Users/Disha/Desktop/codejam/C-large.in"));
  FileWriter fw = new FileWriter("C:/Users/Disha/Desktop/codejam/C-large.out");*/

  int N = new Integer (in.readLine());
  int count = 0;
  for (int cases = 1; cases <= N; cases++) {
	  count = 0;
	  String[] ss = in.readLine().split(" ");
	  int a = Integer.parseInt(ss[0]);
	  int b = Integer.parseInt(ss[1]);
      for (int here = a; here <= b; here++) {
		  int len = Integer.toString(here).length();   	  
		  int len2 = (int) (Math.pow(10, (len-1)));
    	  int num2 = 0;    	  
    	  int num1 = here;
    	  for(int i=0; i<= (len - 1) ; i++){
    		  num2 = (10 * (num1 % len2)) + (num1 / len2);
    		  while(Integer.toString(num2).length() < len){
    			  num2 = num2*10;
    			  i++;
    		  }
    		  
    		  if (num2 == here){
    			  break;
    		  }
    		  if ((num2 <= b) && (num2 > here)){
    		  count ++;
    		  }
    		  num1 = num2;
    	  }
      }
    	  fw.write ("Case #" + cases + ": " + count + "\n" );
      }
  fw.flush();
  fw.close();
  }}
