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.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;


public class C {

	Scanner in;
	public C()
	{
		in = new Scanner(System.in);
		int t = in.nextInt();               // number of test cases ...:)
		for(int l=1;l<=t;l++)
		{
			int n = in.nextInt();           // got n 
            
			int m = in.nextInt();           // got m
			
			int temp=0;                     // For Every data set it has to change 
			int temp2=0;
			int reverse=0;
			int reverse2=0;
			int count=0;
			
			if(n>=10 &&m<100)
			{
				for(int i=n;i<=m;i++)
				{
					temp=i;
					while( temp != 0 )
				      {
				          reverse = reverse * 10;
				          reverse = reverse +temp%10;
				          temp = temp/10;
				      }
					
					
					
					
					if((reverse>=n)&&(reverse<=m)&&(reverse!=i))
					{
						count++;
						
					}
					reverse=0;
				
				}
				
				count=count/2;
			}
			if(n>99 && m<=1000)
			{
				for(int i=n;i<=m;i++)
				{
					 temp=temp2=i;
					
				     
				     reverse = reverse +temp%10;
				     reverse2 = reverse2+temp%100;
				     temp = temp/10;
				     temp2=temp2/100;
				     reverse = (reverse * 100)+temp;      //one position replaced 
				     reverse2= (reverse2*10)+temp2;       //two position interchange
					
					 
					
					if((reverse>=n)&&(reverse<=m)&&(reverse!=i))
						
					{
						count++;
					}
					reverse=0;
					
                    if((reverse2>=n)&&(reverse2<=m)&&(reverse2!=i))
						
					{
						count++;
					}
					reverse2=0;
				
			}
				count=count/2;
		}
			System.out.printf("Case #%d: %d\n", l,count);
	}
	
	}
	public static void main(String[] args) {
		
		try
		{
			String inp="C-small-attempt0";
			System.setIn(C.class.getResourceAsStream(inp+".in"));
			System.setOut(new PrintStream(new File("outputC.out")));
			
		}
		catch(FileNotFoundException e)
		{
			e.printStackTrace();
		}
		
		new C();

	}

}
