import java.io.*;

class code1
{
	public static void main(String args[]) throws Exception 
	{
		File ii = new File ("C-small-attempt1.in");
		FileInputStream fis = new FileInputStream(ii);
		BufferedReader  br = new BufferedReader(new InputStreamReader (fis));
		int cases = Integer.parseInt(br.readLine());
		FileOutputStream fout = new FileOutputStream ("output.txt");
		DataOutputStream dout = new DataOutputStream (fout);
		int total=0;
		for(int i=0;i<cases;i++){
		String temp = br.readLine();
		String parts [] = temp.split(" ");
		int lower = Integer.parseInt(parts[0]);
		int upper = Integer.parseInt(parts[1]);
		System.out.println(lower+" "+upper);
		
		for(int j=lower;j<=upper;j++)
		{
			int abc = j;int length=0;
			if(j<10)continue;
			while (abc!=0){abc/=10;length++;}
			abc=j;
			for(int m=0;m<length-1;m++){
				int shift = abc%10;
				abc=abc/10;
				System.out.println("hi "+j);
				abc=abc+shift*power(10,length-1);
				if(abc<=upper&&shift!=0&&abc>j)total++;
				System.out.println(total);
			}
		}
 		dout.writeBytes("Case #"+(i+1)+ ": "+total+"\n");
 		total=0;
		}//for close
		
	}

	private static int power(int i, int j) {
		int no=1;
		for(int a=0;a<j;a++){no=10*no;}
		return no;
	}
}
import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;

public class EasyNumbers { 
	public static void main(String[] args) throws Exception{
		PrintWriter out =new PrintWriter(new File("../easyNumbers/src/numberrr.out"));
		Scanner s =new Scanner(new File("../easyNumbers/src/number.in"));
		int ans,div,d,k,n1,n2,j,a,a1,b;
		int i,t;
		t = s.nextInt();
		for(int w = 1; w<=t; w++){
			a = s.nextInt();
			b = s.nextInt();
			ans=0;
			i=0;
			a1 = a;
			while(a1!=0){
				a1/=10;
				i++;
			}
			for(j=a;j<=b;j++){
				n2=j;
				for(k=0;k<i-1;k++){
					n1 = j;
					div = 1;
					while(n1 > 9){
						n1 = n1 / 10;
						div = div * 10;
					}
					d = n2 % 10;
					n2 = n2 / 10;
					n2 = n2 + d * div ;
					if(n2<=b && n2>=a && n2!=j && j<n2)
						ans++;                           
					if(n2==j)
						break;
				}
			}
		System.out.println("Case #"+ w +  ": " +ans);
		}
	}
}