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.*;
import java.util.HashSet;
import java.util.Scanner;


public class RecycledNumbers {

	static String outputFile, inputFile;
	public static void main(String[] args) throws IOException   {
		if (args.length != 2)
			return;
		inputFile = args[0];
		outputFile = args[1];

		// Create FileReader Object
		FileReader inputFileReader = new FileReader(inputFile);
		FileWriter outputFileReader = new FileWriter(outputFile);

		// Create Buffered/PrintWriter Objects
		BufferedReader inputStream = new BufferedReader(inputFileReader);
		PrintWriter outputStream = new PrintWriter(outputFileReader);
		
		Scanner scanner;
		String inLine = null;
		int cases = Integer.parseInt(inputStream.readLine().trim());
		int a, b;
		for (int i = 1; i < cases + 1; i++) {
			inLine = inputStream.readLine().trim();
			scanner = new Scanner(inLine);
			
			a = scanner.nextInt();
			b = scanner.nextInt();
			outputStream.println("Case #"+i+": "+getNumRecycledNumbers(a,b));
		}
		
		
		outputStream.close();
	}
	
	private static int getNumRecycledNumbers(int a, int b){
		boolean[] isChecked = new boolean[b-a+1];
		String numStr, newNumStr;
		int totalPairs = 0, newNum, numPairs=1;
		
		for (int t = a; t <= b; t++){
			if (isChecked[t-a])continue;
			
			isChecked[t-a]=true;
			numStr = "" + t ;
			numPairs = 1;
			for (int i = numStr.length()-1; i>0; i--){
				newNumStr = numStr.substring(i)+numStr.substring(0, i);
				newNum = Integer.parseInt(newNumStr);
				if (newNum < a || newNum > b ||isChecked[newNum-a]) continue;
				else {
					isChecked[newNum-a] = true;
					numPairs++;
				}
			}
			if (numPairs >2){
				numPairs = getFactorial(numPairs) / ((getFactorial(numPairs-2)*2));
			}else if (numPairs ==2){
				numPairs = 1;
			} else {
				numPairs = 0;
			}
			totalPairs += numPairs;
		}
		
		
		return totalPairs;
	}
	
	private static int getFactorial(int n){
		int result = 1;
		while (n > 1){
			result *= n;
			n--;
		}
		return result;
	}

}
