package jp.funnything.competition.util;

import java.math.BigInteger;

/**
 * Utility for BigInteger
 */
public class BI {
    public static BigInteger ZERO = BigInteger.ZERO;
    public static BigInteger ONE = BigInteger.ONE;

    public static BigInteger add( final BigInteger x , final BigInteger y ) {
        return x.add( y );
    }

    public static BigInteger add( final BigInteger x , final long y ) {
        return add( x , v( y ) );
    }

    public static BigInteger add( final long x , final BigInteger y ) {
        return add( v( x ) , y );
    }

    public static int cmp( final BigInteger x , final BigInteger y ) {
        return x.compareTo( y );
    }

    public static int cmp( final BigInteger x , final long y ) {
        return cmp( x , v( y ) );
    }

    public static int cmp( final long x , final BigInteger y ) {
        return cmp( v( x ) , y );
    }

    public static BigInteger div( final BigInteger x , final BigInteger y ) {
        return x.divide( y );
    }

    public static BigInteger div( final BigInteger x , final long y ) {
        return div( x , v( y ) );
    }

    public static BigInteger div( final long x , final BigInteger y ) {
        return div( v( x ) , y );
    }

    public static BigInteger mod( final BigInteger x , final BigInteger y ) {
        return x.mod( y );
    }

    public static BigInteger mod( final BigInteger x , final long y ) {
        return mod( x , v( y ) );
    }

    public static BigInteger mod( final long x , final BigInteger y ) {
        return mod( v( x ) , y );
    }

    public static BigInteger mul( final BigInteger x , final BigInteger y ) {
        return x.multiply( y );
    }

    public static BigInteger mul( final BigInteger x , final long y ) {
        return mul( x , v( y ) );
    }

    public static BigInteger mul( final long x , final BigInteger y ) {
        return mul( v( x ) , y );
    }

    public static BigInteger sub( final BigInteger x , final BigInteger y ) {
        return x.subtract( y );
    }

    public static BigInteger sub( final BigInteger x , final long y ) {
        return sub( x , v( y ) );
    }

    public static BigInteger sub( final long x , final BigInteger y ) {
        return sub( v( x ) , y );
    }

    public static BigInteger v( final long value ) {
        return BigInteger.valueOf( value );
    }
}

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

/**
 *
 * @author Dimitris
 */
import java.io.*;

public class trito {
    
  File ffff;
  FileReader fr;
  BufferedReader br;
 
  File fout;       
  FileWriter fw;
  BufferedWriter bw; 
  
    public static void main(String [] args){
        trito t=new trito();
      //  System.out.println(t.convert(109,121)); 
        t.run();
       
    }
    
 public void run(){
     try{
        ffff=new File("C:\\Users\\Dimitris\\Documents\\NetBeansProjects\\jam\\src\\C-small-attempt0.in");
        fr=new FileReader(ffff);
        br=new BufferedReader(fr);
    
        fout=new File("C:\\Users\\Dimitris\\Documents\\NetBeansProjects\\jam\\src\\output.out");
        fw=new FileWriter(fout);
        bw=new BufferedWriter(fw);
        
        
        int lo=new Integer(br.readLine());
        
        for(int i=1;i<=lo;i++){
            String s=br.readLine();
            String [] s2=s.split(" ");
           
            int [] tok=new int[s2.length];
            for(int iii=0;iii<s2.length;iii++) tok[iii]=new Integer(s2[iii]) ;
            
            String r=Integer.toString(convert(tok[0],tok[1]));
            bw.write("Case #"+i+": "+r);
            bw.write('\n');
            
        }
       br.close();
       bw.close();
     }
     catch(Exception e){
         e.printStackTrace();
     }
 }   

 
 public int convert(int aa,int bb){
  int A=aa;
  int B=bb;
  int res=0;
  
  for(int m=B;m>A;m--){  
    
    for(int n=A;n<m;n++){   
        
        
                 
        String s=Integer.toString(n);
         
        char[] c=new char[s.length()];
        for(int i=0;i<s.length()-1;i++){
          
           c[0]=s.charAt(s.length()-1);
           
           for(int i2=1;i2<s.length();i2++){
             c[i2]=s.charAt(i2-1);
             
           }
           s=new String(c);
           
           int neo=new Integer(s);
          if(c[0]==0) continue;
            
           if(neo==m){
                 
                 res++;
                 break;
           }
        }
     
     } 
    }
    
    return res;
   
  }
}
    