import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
import java.io.File;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;


public final class RecycledNumbersAnalyzer {

	private static boolean isRecycledPair (final int n, final int m) {
		if (n < 10)
			return false;

		final String nFirstDigit = Character.toString((Integer.toString(n)).charAt(0));
		final String mString = Integer.toString(m);
		final int mLength = mString.length();

		int mIndexSearch = 0;
		int mIndex;
		while ((mIndex = mString.indexOf(nFirstDigit, mIndexSearch)) != -1) {
			final int recycledM = Integer.valueOf(mString.substring(mIndex, mLength) + mString.substring(0, mIndex));
			if (recycledM == n)
				return true;
			//else
			mIndexSearch = mIndex+1;  //increment
		}
		return false;
	}

	private static Integer[] recycledPairs (final int n, final int b) {
		final String nString = Integer.toString(n);
		final int nLength = nString.length();

		int nDigitIndex = 1;
		final Set<Integer> recycledNs = new HashSet<Integer>();
		while (nDigitIndex < nLength) {
			final int recycledN = Integer.valueOf(nString.substring(nDigitIndex, nLength) + nString.substring(0, nDigitIndex));
			if (recycledN > n && recycledN <= b) {
				//n is a possible m
				/*if (!isRecycledPair(n, recycledN))  //debug
					throw new RuntimeException ("bad recycled N ; n=" + n + ", recycledN=" + recycledN);*/
				recycledNs.add(recycledN);
			}

			++nDigitIndex;  //loop increment
		}

		return recycledNs.toArray(new Integer[] {});
	}

	public static int findRecycledPairsNumber (final int a, final int b) {
		int recycledPairsNumber = 0;
		for (int n = a; n < (b-1); ++n) {
			recycledPairsNumber += (recycledPairs(n, b)).length;
		}
		return recycledPairsNumber;
	}

	private static final String OUTPUT_FILE_EXTENSION = "out";
	private static final String OUTPUT_LINE_FORMAT = "Case #%d: %s";

	public static void main (final String[] args) throws Exception {
		//input init
		if (args.length < 1)
			throw new IllegalArgumentException();

		final String inputFileName = args[0];
		final int lastDotIndex = inputFileName.lastIndexOf('.');
		final String fileName = (lastDotIndex < 0) ? inputFileName : inputFileName.substring(0, lastDotIndex);
		final String outputFileName = fileName + "." + OUTPUT_FILE_EXTENSION;

		final File inputFile = new File(inputFileName);
		final File outputFile = new File(outputFileName);
		Scanner inputScanner = null;
		PrintWriter outputWriter = null;

		try {
			inputScanner = new Scanner(inputFile);
			outputWriter = new PrintWriter(outputFile);
			final int numberLines = inputScanner.nextInt();
			inputScanner.nextLine();  //go to first text line
			for (int i = 0; i < numberLines; ++i) {
				final int n = inputScanner.nextInt();
				final int m = inputScanner.nextInt();
				final int recycledPairsNumber = findRecycledPairsNumber(n, m);
				outputWriter.println(String.format(OUTPUT_LINE_FORMAT, i+1, recycledPairsNumber));
			}
		} catch (final NoSuchElementException noSuchElementException) {
			System.err.println("invalid input");
			throw noSuchElementException;
		} finally {
			if (inputScanner != null) {
				inputScanner.close();
			}
			if (outputWriter != null) {
				outputWriter.flush();
				outputWriter.close();
			}
		}
	}

}
