import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

	}
	
	
}
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class RecycledNumbers {

	private long low;
	private long high;
	private Map<Long, Boolean> map = new HashMap<Long, Boolean>();
	private int recycycled = 0;

	public static void main(String[] args) throws NumberFormatException,
			IOException {

		File file = new File("C:\\Users\\xebia\\Downloads\\C-small-attempt0.in");

		FileInputStream fis = new FileInputStream(file);
		DataInputStream in = new DataInputStream(fis);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		int numberOfTestCases = new Integer(br.readLine());
		for (int j = 0; j < numberOfTestCases; j++) {

			RecycledNumbers re = new RecycledNumbers();
			String[] strings = br.readLine().split(" ");
			String s = strings[0];
			String s2 = strings[1];
			long high = new Long(s2);
			long low = new Long(s);
			int numberOfDigits = s.length();
			for (long i = low; i <= high; i++) {
				int roundOffFigure = 1;
				for (int k = 0; k < numberOfDigits - 1; k++) {
					roundOffFigure = roundOffFigure * 10;
					long lastDigit = (long) (i % roundOffFigure);
					String str = "" + lastDigit;

					if (str.length() == k + 1) {

						long startingCombination = (long) (i / roundOffFigure);
						if (lastDigit == 0) {
							continue;
						}
						long number = (long) (lastDigit
								* (Math.pow(10, numberOfDigits - str.length())) + startingCombination);

						if (number >= low && number <= high) {
							if (number != i) {
								Boolean bool = re.map.get(number * i);
								if (bool == null) {
									re.map.put(number * i, true);
									re.recycycled++;
								}

							}
						}
					}
				}

			}
			System.out.println("Case #" + (j + 1) + ": " + re.recycycled);
		}
	}

	public void setLow(long low) {
		this.low = low;
	}

	public long getLow() {
		return low;
	}

	public void setHigh(long high) {
		this.high = high;
	}

	public long getHigh() {
		return high;
	}

	public void setRecycycled(int recycycled) {
		this.recycycled = recycycled;
	}

	public int getRecycycled() {
		return recycycled;
	}

}
