/*
 * 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.File;
import java.util.Scanner;
import java.util.Vector;

class C {
    static int count=0;
    public static void main(String[] args) {
        if(args.length==100){
            System.out.println("Error	::  Please provide input file name as first command line argument");
	    System.out.println("Usage	::  java Main <file_name>");
	    System.out.println("Example	::  java Main A-small-practice.in");
        }
   	else{
            try{
                Scanner input=new Scanner(new File("C-small-attempt2 (1).in"));
                //Scanner input=new Scanner(new File("input.txt"));
                //System.out.println("Reading Input from "+ args[0]+" file");
                int no=input.nextInt();

                int lim[][]=new int[no][2];

                for(int i=0;i<no;i++){
                    lim[i][0]=input.nextInt();
                    lim[i][1]=input.nextInt();
                }

               /*//Display
               for(int i=0;i<no;i++){
                   System.out.println(lim[i][0]+" "+lim[i][1]);
               }*/

               //Alogrithm
               for(int i=0;i<no;i++){
                   for(int j=lim[i][0];j<=lim[i][1];j++){
                       findIt(new Integer(j).toString(),lim[i][1]);
                   }
                   System.out.println("Case #"+(i+1)+": "+ count);
                   count=0;
               }
            }catch(Exception e){
                e.printStackTrace();
             }
        }
   }
   private static void findIt(String s,int limit) {
       Vector old=new Vector();
       if(s.length()!=1)
       for(int i=0,j=s.length()-1;j>0;j--){
           String newS=s.substring(j, s.length())+s.substring(i, j);
           if(!newS.startsWith("0")&&!s.equals(newS)&&new Integer(newS).intValue()>new Integer(s).intValue()&&new Integer(newS).intValue()<=limit){
               if(!old.contains(newS)){
                old.add(newS);
                //System.out.println(newS);
                count++;
               }
           }
       }
   }
}