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.FileWriter;
import java.util.HashMap;
import java.util.Scanner;


public class RecycledNumbers {


	public static void main(String[] args) throws Exception {
		RecycledNumbers recycledNumbers = new RecycledNumbers();
		// file name
		String fileName = "recycled_numbers";
		
		// file variable
		File inputFile = new File(fileName + ".in");
		File outputFile = new File(fileName + ".out");
		Scanner scanner = new Scanner(inputFile);
		FileWriter writer = new FileWriter(outputFile);


		// problem variable
		int totalCase;
	
		// get total case
		totalCase = Integer.parseInt(scanner.nextLine());
		System.out.println("Total case:"+totalCase);
		
		for (int caseIndex = 1; caseIndex <= totalCase; caseIndex++) {

			String lineDetail = scanner.nextLine();
			String[] inputArray = lineDetail.split(" ");
			String min =  inputArray[0];
			String max =  inputArray[1];
			
			int  possibleCases = 0;
			
			possibleCases = recycledNumbers.findPossibleCases(min, max);
			
			String output = "Case #" + caseIndex + ": " + possibleCases;		
			System.out.println(output);
			writer.write(output + "\n");
		}
		scanner.close();
		writer.close();
	}
	
	private int findPossibleCases(String min, String max){
		int possibleCases = 0;
		int startVal = Integer.parseInt(min);
		int endVal = Integer.parseInt(max);
		int n,m = 0;
		HashMap<String, String> usedPattern = new HashMap<String, String>();
		
		for(int i=startVal; i<endVal; i++){
			n = i;
			String inputStr = ""+i;
			String shiftStr = "";
			char[] charArr = inputStr.toCharArray();
		
			usedPattern = new HashMap<String, String>();
			
			//startAt
			for(int j= 0; j<charArr.length; j++){
				shiftStr = "";
				// loop to get shift data
				for(int k= j; k<charArr.length+j; k++){
					shiftStr += charArr[k%charArr.length];
				}
				m = Integer.parseInt(shiftStr);
				if( (m > n) && (m <=endVal)){
					if(!usedPattern.containsKey(shiftStr) ){
						possibleCases++;
					}
				}
				
				// keep the temp of shifting data
				usedPattern.put(shiftStr, shiftStr);
			}
			m = 0;

		}
		return possibleCases;
	}
}
