import java.io.*;
import java.util.*;

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}

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

}
