import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

	}
	
	
}
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Scanner;


public class done {
	public static void main(String args[]) throws IOException
	{
Hashtable a = new Hashtable();
ArrayList<Integer> f = new ArrayList();


Scanner in = new Scanner(System.in);



DataInputStream d = new DataInputStream(new BufferedInputStream(new FileInputStream("C:/Users/ANKIT/Desktop/C-small-attempt0.in")));

//DataInputStream d = new DataInputStream(new BufferedInputStream(new FileInputStream("C:/Users/ANKIT/Desktop/hj.txt")));

String num = d.readLine();

int num1;

num1 = Integer.parseInt(num);
for(int i=0;i<num1;i++)
{

String  j = (d.readLine());

String [] a1 = j.split(" ");

Integer A = Integer.parseInt(a1[0]);
Integer B = Integer.parseInt(a1[1]);




int o=0;
String m = "" ;

for(Integer k=A;k<=B;k++)
{
	
	for (Integer y= k+1;y<=B;y++)
	{
	
		String a11 = Integer.toString(k);
		String b11 =Integer.toString(y);

		
		for(int t=1;t<a11.length();t++)
		{
			
			 if((a11.substring(t, a11.length())+a11.substring(0,t)).equals(b11))
			{
				o++;
				break;
			}
			
			
		
		}
}

}
f.add(o);
PrintWriter f11 =new PrintWriter("hello");

for(int y=0;y<f.size();y++)
	
{
	
	
	Integer h  = f.get(y);

f11.print("Case #"+(1+y)+": "+h+'\n');

}
f11.close();
	}
	
	}
}