package jp.funnything.competition.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;

import org.apache.commons.io.IOUtils;

public class QuestionReader {
    private final BufferedReader _reader;

    public QuestionReader( final File input ) {
        try {
            _reader = new BufferedReader( new FileReader( input ) );
        } catch ( final FileNotFoundException e ) {
            throw new RuntimeException( e );
        }
    }

    public void close() {
        IOUtils.closeQuietly( _reader );
    }

    public String read() {
        try {
            return _reader.readLine();
        } catch ( final IOException e ) {
            throw new RuntimeException( e );
        }
    }

    public BigDecimal[] readBigDecimals() {
        return readBigDecimals( " " );
    }

    public BigDecimal[] readBigDecimals( final String separator ) {
        final String[] tokens = readTokens( separator );

        final BigDecimal[] values = new BigDecimal[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = new BigDecimal( tokens[ index ] );
        }

        return values;
    }

    public BigInteger[] readBigInts() {
        return readBigInts( " " );
    }

    public BigInteger[] readBigInts( final String separator ) {
        final String[] tokens = readTokens( separator );

        final BigInteger[] values = new BigInteger[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = new BigInteger( tokens[ index ] );
        }

        return values;
    }

    public int readInt() {
        final int[] values = readInts();

        if ( values.length != 1 ) {
            throw new IllegalStateException( "Try to read single interger, but the line contains zero or multiple values" );
        }

        return values[ 0 ];
    }

    public int[] readInts() {
        return readInts( " " );
    }

    public int[] readInts( final String separator ) {
        final String[] tokens = readTokens( separator );

        final int[] values = new int[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = Integer.parseInt( tokens[ index ] );
        }

        return values;
    }

    public long readLong() {
        final long[] values = readLongs();

        if ( values.length != 1 ) {
            throw new IllegalStateException( "Try to read single interger, but the line contains zero or multiple values" );
        }

        return values[ 0 ];
    }

    public long[] readLongs() {
        return readLongs( " " );
    }

    public long[] readLongs( final String separator ) {
        final String[] tokens = readTokens( separator );

        final long[] values = new long[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = Long.parseLong( tokens[ index ] );
        }

        return values;
    }

    public String[] readTokens() {
        return readTokens( " " );
    }

    public String[] readTokens( final String separator ) {
        return read().split( separator );
    }
}

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

package codejam;

/**
 *
 * @author PRATIK
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int test=args.length/2;
      

        int len=0,i,m,tem,val=0,l=0,count=0,count1=0,j=1,k;
        char arr[];
        String sec;
        int secnd;
        char temp;
        int f=1;
        int[] array=new int[500];
        int[][] array1=new int[1000][2];
        while(test!=0)
        {
            int start=Integer.parseInt(args[f]);
            int end=Integer.parseInt(args[f+1]);
            while(start<end)
            {
            String st=String.valueOf(start);
            len=st.length();
            char arr1[]=new char[len];
            if(len>1)
            {
            for(i=0;i<len;i++)
            {
                arr=st.toCharArray();

                temp=arr[len-1];
                for(k=1;k<len;k++)
                    arr1[k]=arr[k-1];
                arr1[0]=temp;
                st=String.valueOf(arr1);
                val=Integer.parseInt(st);
                if(val<=end && val>start)
                {
                    array1[l][0]=start;
                    array1[l][1]=Integer.parseInt(st);
                    l++;
                    count1++;
                }

            }
            }
            start++;
            }
            for(i=0;i<l;i++)
            {
                for(k=i+1;k<l;k++)
                {
                    if(array1[k][0]==array1[i][0] && array1[k][1]==array1[i][1])
                    {
                        if(count1>0)
                     count1--;
                    }
                }
            }


            System.out.println("Case #"+j+ ": "+count1);
            j++;
            test--;
            count1=0;
            f=f+2;
            l=0;
        }
    }

}
