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 );
    }
}

package jam2012.qround;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;

public class RPair {
	int n;
	int m;
	public RPair(int n,int m){
		this.n = n;
		this.m = m;
	}
	public static void main(String args[])
	{
		int line = 0;
		try{
			BufferedReader br = new BufferedReader(new FileReader("C-small-attempt0.in"));
			BufferedWriter bw = new BufferedWriter(new FileWriter("C-small-attempt0.out"));
			//			BufferedReader br = new BufferedReader(new FileReader("input.in"));
			String str;
			String[] strIn;
			Integer.parseInt(br.readLine());
			while ((str = br.readLine()) != null)   {
				strIn = str.split(" ");
				int min = Integer.parseInt(strIn[0]);
				int max = Integer.parseInt(strIn[1]);
				int count = 0;
				List <RPair>used = new ArrayList<RPair>();
				for(int i=min;i<=max;i++){
					int[] mutList = play(i,min,max);
					for(int j=0;j<mutList.length;j++)
						if(!used.contains(new RPair(i,mutList[j]))){
							count++;
							used.add(new RPair(i,mutList[j]));
						}
				}
				line++;
				//				System.out.println("Case #"+line+": "+count/2);
				bw.write("Case #"+line+": "+count/2);
				bw.newLine();
			}
			br.close();
			bw.close();
		}catch (Exception e){//Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}
	public static int[] play(int num, int min, int max){
		String c = Integer.toString(num);
		int len = c.length();
		List <Integer>mutList = new ArrayList<Integer>();
		for (int i=1;i<len;i++){
			c = Character.toString(c.charAt(len-1)).concat(c.substring(0, len - 1));
			int mut = Integer.parseInt(c);
			if (Integer.toString(mut).length()==len && mut != num && mut >= min && mut <= max)
				mutList.add(mut);
		}

		if (mutList.size() != 0){
			int[] intArray = new int[mutList.size()];
			for (int i = 0; i < mutList.size(); i++) {
				intArray[i] = mutList.get(i);
			}
			return intArray;
		}
		else return new int[0];
	}

}


