package qual;

import java.util.Scanner;

public class RecycledNumbers {

	public static void main(String[] args) {
		new RecycledNumbers().run();

	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int result = solve(A, B);
			System.out.printf("Case #%d: %d\n", t + 1, result);
		}
	}

	public int solve(int A, int B) {
		int result = 0;
		for (int i = A; i <= B; i++) {
			int dig = (int) Math.log10(A/*same as B*/) + 1;
			int aa = i;
			for (int d = 0; d < dig - 1; d++) {
				aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
				if (i == aa) {
					break;
				}
				if (i < aa && aa <= B) {
//					System.out.printf("(%d, %d) ", i, aa);
					result++;
				}
			}
		}
		return result;
	}

}

/* ==========================================================
 *  (C) Copyright 2007-present Facebook. All rights reserved.
 * ==========================================================
 */


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

/**
 * .
 *
 * @author
 */
public class Recycle {
    public static void main( String[] args ) throws NumberFormatException,
        IOException {
        final BufferedReader in =
            new BufferedReader( new FileReader(
                    "/Users/oded/a/ttt/src/in.txt" ) );
        final int numLines = Integer.parseInt( in.readLine() );

        for( int i = 0; i < numLines; i++ ) {
            handleLine( in.readLine(), i );
        }
    }

    private static int countDigits( int a ) {
        int count = 0;

        while( a > 0 ) {
            count++;
            a = a / 10;
        }

        return count;
    }

    private static void handleLine( String readLine, int i ) {
        String[] numbers = readLine.split( " " );
        int      a       = Integer.parseInt( numbers[ 0 ] );
        int      b       = Integer.parseInt( numbers[ 1 ] );
        int      count   = 0;
        int      digits  = countDigits( a );

        if( digits > 1 ) {
            int den = 1;

            while( digits > 1 ) {
                den *= 10;
                digits--;
            }

            for( int n = a; n < b; n++ ) {
                int perm = shift( n, den );

                while( perm != n ) {
                    if( perm > n && perm <= b ) {
                        count++;
                    }

                    perm = shift( perm, den );
                }
            }
        }

        System.out.println( "Case #" + ( i + 1 ) + ": " + count );
    }

    private static int shift( int n, int den ) {
        return ( n / den ) + ( n % den ) * 10;
    }
}
