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

import java.io.FileReader;
import java.io.LineNumberReader;
import java.io.PrintStream;

public class RecycledNumbers {
	public boolean testRecycled(int a, int b) {
		String sa = String.valueOf(a);
		String sb = String.valueOf(b);
//		if(sa.indexOf('0')!=-1 || sb.indexOf('0')!=-1)
//			return false;
		int n = sa.length();
		for(int i=0; i<n; i++) {
			StringBuffer buf = new StringBuffer();
			buf.append(sa.substring(n-1));
			buf.append(sa.substring(0,n-1));
			sa = buf.toString();
			if(sb.equals(sa))
				return true;
		}
		return false;
	}
	public static void main(String[] args) throws Exception {
		RecycledNumbers rn = new RecycledNumbers();
		LineNumberReader in = new LineNumberReader(new FileReader(args[0]+".in"));
		String line = null;
		line = in.readLine();
		if(line==null||line.length()==0)
			return;
		int T = 0;
		T = Integer.parseInt(line);
		PrintStream out = new PrintStream(args[0]+".out");
		System.out.println(new java.util.Date());
		for(int k=1; k<=T; k++){
			line = in.readLine();
			String[] data = line.split(" ");
			// brute force
			int n = 0;
			int A = Integer.parseInt(data[0]); 
			int B = Integer.parseInt(data[1]); 
			for(int i = A; i<B; i++) {
				for(int j = i+1; j<=B; j++) {
					if(rn.testRecycled(i, j))
						n++;
				}
			}
			StringBuffer buf = new StringBuffer();
			buf.append("Case #");
			buf.append(k);
			buf.append(": ");
			buf.append(n);
			out.println(buf.toString());
			System.out.println(buf.toString());
		}
		System.out.println(new java.util.Date());
		in.close();
		out.close();
	}

}
