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

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

import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer;

/**
 *
 * @author Leo
 */
public class C {
  public static void main(String[] args) throws FileNotFoundException, IOException {
       
  new C().run();
  }
    
    String inputFile = "txt.in";
     Scanner in;
	
     public void run() throws FileNotFoundException, IOException{
        in = new Scanner(new FileReader(inputFile));
		
        int cases = in.nextInt();
      
          for(int i=1;i<=cases;i++)
          {
        int d=0;
          int  A = in.nextInt();
           int  B = in.nextInt();
          d=howManyDigits(B);
          int c = resolve(A,B,d);
           System.out.println("Case #" + i + ": " + A + " " + B + " " + c);
      
          }

     }

     
     public  int resolve(int a , int b, int d)
     {
        
         int comp1=0;
         int comp2=0;
   
      int m=0;
      int n=0;
       
         
         for(int j=a;j<=b;j++){
         
        if(d==2) {
             m = this.permuteDigits(j);
             if(a<=m && m<=b){ comp1++;}
         }
        
          if(d==3) {
             m = this.permuteDigits3A(j);
             n = this.permuteDigits3B(j);
             if(a<=m && m<=b){ comp2++;}
             if(a<=n && n<=b){ comp2++;}
         }
        
          
         }
         return (comp1)/2 + comp2;
      
         
         }
         
    
     
     
  
  
int howManyDigits(int x){
  
 if(x<10)   return 1;  

    if(10<=x && x<=99)   return 2;  
     if(100<=x && x<=999)   return 3;  
return 0;
}


int permuteDigits3A(int x){
  
int m =0;
int n = 0;
int t=0;
int f=0;

m=x%100;
m=m%10;
n = x/100;
f=x/10;
f=f%10;
t = m*100+n + f*10;
if((m==n && n==f) ||   f==0) t=0;
return t;
}

int permuteDigits3B(int x){
  
int m =0;
int n = 0;
int t=0;
int f=0;

m=x%100;
n = x/10;
f=x%100;
t = m*100+n;
if((m==n && n==f) ||   m==0 ) t=0;
return t;
}

int permuteDigits(int x){
  
int m =0;
int n = 0;
int t=0;

m=x%10;
n = x/10;
t = m*10+n;
if(m==n || n==0 || m==0 ) t=0;
return t;
}

}

