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

package c;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.HashSet;

public class RecycledNumbers {

	public static int getDistinctRecycleCount(int min, int max) {
		HashSet<String> distinctCollection = new HashSet<String>();
		for(int i = min; i <= max; i++) {
			distinctCollection.addAll(getThePossiblePair(i, max));
		}
		return distinctCollection.size();
	}
	
	private static HashSet<String> getThePossiblePair(int theNum, int max) {
		HashSet<String> ret = new HashSet<String>();
		String theNumStr = Integer.toString(theNum);
		for(int n = 1; n < theNumStr.length(); n++) {
			//roll the number 1 time to the left
			char firstChar = theNumStr.charAt(0);
			theNumStr = theNumStr.substring(1) + firstChar;
			int theRolledNum = Integer.parseInt(theNumStr);

			//check if the rolled number is possible
			if((theNum < theRolledNum) && (theRolledNum <= max))
				ret.add(Integer.toString(Math.min(theNum, theRolledNum)) +
						"-" +
						Integer.toString(Math.max(theNum, theRolledNum)));
		}
		return ret;
	}


	public static void main(String[] args) throws Exception {

		//initial reader by args[0]
		BufferedReader r = new BufferedReader(new FileReader(args[0]));
		int cases = Integer.parseInt(r.readLine());

		//initial writer by args[1]
		PrintWriter w = new PrintWriter(args[1]);

		//do
		for(int i = 1; i <= cases; i++) {
			String[] ab = r.readLine().split(" ");
			w.println("Case #" + i + ": " + getDistinctRecycleCount(Integer.parseInt(ab[0]), Integer.parseInt(ab[1])));
		}

		//close file handles
		w.close();
		r.close();
	}

}