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.io.IOException;


public class exo2 {
	
	public static ArrayList<Integer> listeCouple = new ArrayList<Integer>() ;

	public static int T;
	public static int A ;
	public static int B ;
	public static int Result = 0 ;
	static int k ;
	static int l ;
	static int m ;
	static int n ;
	static int o ;
	static int p ;
	static int q ;
	
	public static void digit2(int A,int B,int D){
		k = D%10 ;
		l = (D-k)/10 ;
		if((k*10+l)>=A && (k*10+l)<=B && (k*10+l)>D){
			Result = Result + 1 ;
		}
	}
	public static void digit3(int A,int B,int D){
		k = D%10 ;
		l = ((D-k)%100) /10;
		m = (D-l*10-k ) /100;
		if ((k*100+m*10+l)>=A &&(k*100+m*10+l)<=B && (k*100+m*10+l)>D ) {
			Result = Result + 1 ;	

		}
		if ((l*100+k*10+m)>=A &&(l*100+k*10+m)<=B &&(l*100+k*10+m)>D ) {
			Result = Result + 1 ;
		}
	}
	public static void digit4(int A,int B,int D){
		k = D%10 ;
		l = ((D-k)%100) /10;
		m = (D-l*10-k)%1000 /100 ;
		n = (D-m*100-l*10-k)/1000;
		if ((k*1000+n*100+m*10+l)>=A && (k*1000+n*100+m*10+l)<=B &&(k*1000+n*100+m*10+l)>D ){
			Result = Result + 1 ;	
		}		
		if ((l*1000+k*100+n*10+m)>=A &&(l*1000+k*100+n*10+m)<=B &&(l*1000+k*100+n*10+m)>D ){
			Result = Result + 1 ;
		}
		if ((m*1000+l*100+k*10+n)>=A &&(m*1000+l*100+k*10+n)<=B &&(m*1000+l*100+k*10+n)>D ){
			Result = Result + 1 ;
		}
	}
	public static void digit5(int A,int B,int D){
		k = D%10 ;
		l = ((D-k)%100) /10;
		m = (D-l*10-k)%1000 /100 ;
		n = ((D-m*100-l*10-k)%10000) / 1000;
		o = (D-n*1000-m*100-l*10-k)/10000 ;
		if ((k*10000+o*1000+n*100+m*10+l)>=A && (k*10000+o*1000+n*100+m*10+l)<=B && (k*10000+o*1000+n*100+m*10+l)>D) {
			Result = Result + 1 ;
		}
		if ((l*10000+k*1000+o*100+n*10+m)>=A && (l*10000+k*1000+o*100+n*10+m)<=B && (l*10000+k*1000+o*100+n*10+m)>D ) {
			Result = Result + 1 ;
		}
		if ((m*10000+l*1000*k*100+o*10+n)>=A && (m*10000+l*1000*k*100+o*10+n)<=B && (m*10000+l*1000*k*100+o*10+n)>D){
			Result = Result + 1 ;
		}
		if ((n*10000+m*1000*l*100+k*10+o)>=A && (n*10000+m*1000*l*100+k*10+o)<=B && (n*10000+m*1000*l*100+k*10+o)>D){
			Result = Result + 1 ;
		}
	}
	public static void digit6(int A,int B, int D){
		k = D%10 ;
		l = ((D-k)%100) /10;
		m = (D-l*10-k)%1000 /100 ;
		n = ((D-m*100-l*10-k)%10000) / 1000;
		o = ((D-n*1000-m*100-l*10-k)%100000) /10000;
		p = (D-o*10000-n*1000-m*100-l*10-k)/100000 ;
		if ((k*100000+p*10000+p*1000+n*100+m*10+l)>=A && (k*100000+p*10000+p*1000+n*100+m*10+l)<=B 
				&& (k*100000+p*10000+p*1000+n*100+m*10+l)>D) {
			Result = Result + 1 ;
		}
		if ((l*100000+k*10000+p*1000+o*100+n*10+m)>=A && (l*100000+k*10000+p*1000+o*100+n*10+m)<=B 
				&& (l*100000+k*10000+p*1000+o*100+n*10+m)>D) {
			Result = Result + 1 ;
		}
		if ((m*100000+l*10000*k*1000+p*100+o*10+n)>=A && (m*100000+l*10000*k*1000+p*100+o*10+n)<=B  
				&& (m*100000+l*10000*k*1000+p*100+o*10+n)>D){
			Result = Result + 1 ;
		}
		if ((n*100000+m*10000*l*1000+k*100+p*10+o)>=A && (n*100000+m*10000*l*1000+k*100+p*10+o)<=B  
				&& (n*100000+m*10000*l*1000+k*100+p*10+o)>D){
			Result = Result + 1 ;
		}
		if ((o*100000+n*10000+m*1000*l*100+k*10+p)>=A && (o*100000+n*10000+m*1000*l*100+k*10+p)<=B  
				&& (o*100000+n*10000+m*1000*l*100+k*10+p)>D){
			Result = Result + 1 ;
		}
	}
	public static void digit7(int A,int B,int D){
		k = D%10 ;
		l = ((D-k)%100) /10;
		m = (D-l*10-k)%1000 /100 ;
		n = ((D-m*100-l*10-k)%10000) / 1000;
		o = ((D-n*1000-m*100-l*10-k)%100000) /10000;
		p = ((D-o*10000-n*1000-m*100-l*10-k)%1000000)/100000 ;
		q = (D-p*100000-o*10000-n*1000-m*100-l*10-k)/1000000 ;
		if ((k*1000000+q*100000+p*10000+o*1000+n*100+m*10+l)>=A && (k*1000000+q*100000+p*10000+o*1000+n*100+m*10+l)<=B 
				&& (k*1000000+q*100000+p*10000+o*1000+n*100+m*10+l)>D) {
			Result = Result + 1 ;
		}
		if ((l*1000000+k*100000+q*10000+p*1000+o*100+n*10+m)>=A && (l*1000000+k*100000+q*10000+p*1000+o*100+n*10+m)<=B 
				&& (l*1000000+k*100000+q*10000+p*1000+o*100+n*10+m)>D ) {
			Result = Result + 1 ;
		}
		if ((m*1000000+l*100000+k*10000+q*1000+p*100+o*10+n)>=A && (m*1000000+l*100000+k*10000+q*1000+p*100+o*10+n)<=B  
				&& (m*1000000+l*100000+k*10000+q*1000+p*100+o*10+n)>D){
			Result = Result + 1 ;
		}
		if ((n*1000000+m*100000+l*10000+k*1000+q*100+p*10+o)>=A && (n*1000000+m*100000+l*10000+k*1000+q*100+p*10+o)<=B  
				&& (n*1000000+m*100000+l*10000+k*1000+q*100+p*10+o)>D){
			Result = Result + 1 ;
		}
		if ((o*1000000+n*100000+m*10000+l*1000+k*100+q*10+p)>=A && (o*1000000+n*100000+m*10000+l*1000+k*100+q*10+p)<=B  
				&& (o*1000000+n*100000+m*10000+l*1000+k*100+q*10+p)>D){
			Result = Result + 1 ;
		}
		if ((p*1000000+o*100000+n*10000+m*1000+l*100+k*10+q)>=A && (p*1000000+o*100000+n*10000+m*1000+l*100+k*10+q)<=B  
				&& (p*1000000+o*100000+n*10000+m*1000+l*100+k*10+q)>D){
			Result = Result + 1 ;
		}
	}

	public static void traiter(int A,int B, int j) {
		int D = A ;
		if (B<10) {
			Result = 0 ;			
		}
		else if (B<=100){
			for (int i=0;i<(B-A);i++){
				digit2(A,B,D+i);
			}
		}
		else if(B<1000){
			for (int i=0;i<(B-A);i++){
				digit3(A,B,D+i);
			}
		}
		else if(B<10000){
			for (int i=0;i<(B-A);i++){
				digit4(A,B,D+i);
			}
		}
		else if(B<100000){
			for (int i=0;i<(B-A);i++){
				digit5(A,B,A+i);
			}
		}
		else if(B<1000000){
			for (int i=0;i<(B-A);i++){
				digit6(A,B,A+i);
			}
		}
		else if(B<10000000){
			for (int i=0;i<(B-A);i++){
				digit7(A,B,A+i);
			}
		}
		
	}
	public static void read(String arg)  throws java.io.IOException {
		java.util.Scanner lecteur ;		
		java.io.File fichier = new java.io.File(arg);
		lecteur = new java.util.Scanner(fichier);
	
		T = lecteur.nextInt() ;
		for (int i=0;i<=T;i++){
			if (lecteur.hasNextInt()){
				A = lecteur.nextInt();
				B = lecteur.nextInt() ;
				traiter(A,B,i);
				System.out.println("Case #"+(i+1)+": "+Result);
			}
			Result = 0 ;
			listeCouple.removeAll(listeCouple) ;
		}	
	}
	

	
	public static void main(String[] args) throws IOException{
		String arg = null;
		arg = "C-large.in" ;
		read(arg) ;
	}
}