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.
 */
package recyclednumbers;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Vector;

/**
 *
 * @author Kholoud
 */
public class RecycledNumbers {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            FileInputStream ifstream = new FileInputStream("C:\\Users\\Kholoud\\Downloads\\C-small-attempt0.in");
            DataInputStream in = new DataInputStream(ifstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            int n = Integer.parseInt( br.readLine());
            String line;
            for(int i = 0;i<n;i++)
            {
                int count = 0;
                line = br.readLine();
                int A = Integer.parseInt(line.split(" ")[0]);
                int B = Integer.parseInt(line.split(" ")[1]);
                Vector<String> rotatedNumbers;
                for(int num = A;num<=B;num++)
                {
                    rotatedNumbers = new Vector<String>();
                    String rotatedNum = String.valueOf(num);
                    for(int j = 0;j<String.valueOf(num).length()-1;j++)
                    {
                        rotatedNum = rotate(rotatedNum);
                        if(num < Integer.parseInt(rotatedNum) &&Integer.parseInt(rotatedNum) <= B && !rotatedNumbers.contains(rotatedNum))
                        {
                            rotatedNumbers.add(rotatedNum);
                            count++;
                        }
                    }
                }
                System.out.println("Case #" + (i + 1) + ": " + count);
            }
            
        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
    public static String rotate(String num)
    {     
        String rotated = num.charAt(num.length()-1) + num.substring(0, num.length()-1);       
        return rotated;
    }
}
