import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
import java.util.ArrayList;
import java.util.HashSet;


public class ProbC {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ArrayList<String> in=Utils.readFile("C-large.in.in");
		ArrayList<String> out =new ArrayList<String>();
		//int[][] matrix=new int[100000][100000];
		for (int i = 1; i < in.size(); i++) {
			String[] str=in.get(i).split(" ");
			int A= Integer.parseInt(str[0]);
			int B= Integer.parseInt(str[1]);
			int numA=numDigit(A);
			int count=0;
			HashSet<Integer> checkDup=new HashSet<Integer>();
			for(int j=A;j<=B;j++){
				for(int pos=1;pos<numA;pos++){
					int recycle=rotate(j,pos);
					//System.out.println(i+": "+j+ " vs "+recycle);
					if(recycle<=B&&j<recycle){
						if(!checkDup.contains(recycle)){
							count++;//System.out.println("**************"+j+"<=>"+recycle);
							checkDup.add(new Integer(recycle));
						}		
						//System.out.println(i+": "+j +" vs "+recycle+"**********");	
					}
				}
				checkDup.clear();
			}
			out.add("Case #"+i+": "+ count);
			
			
			
		}
		Utils.writeFile(out, "c-large");
//		for(int i=1000;i<1200;i++){
//			System.out.println(i+"=>"+rotate(i,4));
//		}

	}

	private static int myExp(int e){
		if(e==1)
			return 1;
		if(e==2)
			return 10;
		if(e==3)
			return 100;
		if(e==4)
			return 1000;
		if(e==5)
			return 10000;
		if(e==6)
			return 100000;
		//if(e==7)
		return 1000000;
		
	}
	private static int rotate(int A,int pos) {
		int num=numDigit(A);
		if(pos==1)
			return (A%10)*myExp(num-pos+1)+A/10;
		if(pos==2)
			return (A%100)*myExp(num-pos+1)+A/100;
		if(pos==3)
			return (A%1000)*myExp(num-pos+1)+A/1000;
		if(pos==4)
			return (A%10000)*myExp(num-pos+1)+A/10000;
		if(pos==5)
			return (A%100000)*myExp(num-pos+1)+A/100000;
		if(pos==6)
			return (A%1000000)*myExp(num-pos+1)+A/1000000;
		//if(pos==7)
		return (A%10000000)*myExp(num-pos+1)+A/10000000;
	}
	private static int numDigit(int A) {
		if(A/1000000>0)
		return 7;
		if(A/100000>0)
			return 6;
		if(A/10000>0)
			return 5;
		if(A/1000>0)
			return 4;
		if(A/100>0)
			return 3;
		if(A/10>0)
			return 2;
		return 1;
	}

}
