package fixjava;

public class StringUtils {

	/** Repeat the given string the requested number of times. */
	public static String repeat(String str, int numTimes) {
		StringBuilder buf = new StringBuilder(Math.max(0, str.length() * numTimes));
		for (int i = 0; i < numTimes; i++)
			buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the left hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padLeft(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(padChar);
		for (int i = 1, mi = bufSize - str.length(); i < mi; i++)
			buf.append(padChar);
		buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the right hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padRight(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(str);
		buf.append(padChar);
		while (buf.length() < bufSize)
			buf.append(padChar);
		return buf.toString();
	}

	/** Intern all strings in an array, skipping null elements. */
	public static String[] intern(String[] arr) {
		for (int i = 0; i < arr.length; i++)
			arr[i] = arr[i].intern();
		return arr;
	}

	/** Intern a string, ignoring null */
	public static String intern(String str) {
		return str == null ? null : str.intern();
	}

}

import static java.lang.System.in;
import static java.lang.System.out;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class Recycled {

	
	public static void main(String[] args) throws IOException {
		Scanner asdf = new Scanner(in);
		Scanner file = new Scanner(new File("C-large.in"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("C-large.out")));
		int t = file.nextInt();
		
		for(int r=1; r<=t; r++){
			run(r, file, out, asdf);
		}
		
		out.close();
	}
	
	public static void run(int r, Scanner file, PrintWriter out, Scanner asdf){
		
		int a = file.nextInt();
		int b = file.nextInt();
		int count = 0;
		ArrayList<Integer> list = new ArrayList<Integer>();
		
		/*for(int s=1; s<=Integer.toString(b).length()/2+1; s++)
			for(int x=a; x<=b; x++)
				for(int y=b; y>=x; y--)
					if(!list.contains(x*y) && x!=y && x==rotateDig(y, s)){
						count++;
						list.add(x*y);
						//System.out.println(x+" "+y);
					}*/
		
		int l = Integer.toString(b).length();
		for(int z=a; z<=b; z++){
			for(int s=1; s<=l; s++){
				int temp = rotateDig(z,s);
				if(temp>z && temp<=b){
					if(list.isEmpty())
						count++;
					else if(!list.isEmpty() && !(temp==list.get(list.size()-1)))
						count++;
					list.add(temp);
					//System.out.println(rotateDig(z,s));
				}
			}
		}
		
		
		//System.out.println("Case #"+r+": "+count);
		out.println("Case #"+r+": "+count);
	}
	

	
	public static int rotateDig(int n, int shift){
		
		String s = Integer.toString(n);
		String t = "";
		
		t = s.substring(shift);
		t += s.substring(0,shift);
		
		return Integer.parseInt(t);
	}


}
