import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		int casos=1, a, b, n, m, cont;
		while(t!=0){
			a=sc.nextInt();
			b=sc.nextInt();
			if(a>b){
				int aux=a;
				a=b;
				b=aux;
			}
			System.out.printf("Case #%d: ",casos++);
			if(a==b){
				System.out.printf("%d\n",0);
			}else{
				cont=0;
				for(n=a;n<b;n++){					
					for(m=n+1;m<=b;m++){					
						if(isRecycled(n,m)) cont++;
					}
				}
				System.out.printf("%d\n",cont);
			}
			t--;
		}		
	}
	public static boolean isRecycled(int n1, int n2){
		String s1, s2, aux;
		s1 =  String.valueOf( n1 );
		s2 =  String.valueOf( n2 );		
		boolean r = false;		
		for(int i=0;i<s1.length();i++){
			aux="";
			aux=s1.substring(i,s1.length())+s1.substring(0,i);
//			System.out.println(aux);
			if(aux.equals(s2)){
				r=true;
				break;
			}
		}		
		return r;
	}
}

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;


public class G2 
{
	 private Scanner reader;
	 private FileWriter fstream;
	 private BufferedWriter out;
	 String nextline;
	 int noLines;
	 int intA;
	 int intB;
	 int lineIndex=1;
	 int value=0;
	 
	 
	 public boolean isValid(int n,int m)
	 {
		 return (!(n==m)&&(intA<=n)&&(n<m)&&(m<=intB));
		 	
	 }
	 public void initiateFiles()
	{
			try 
			{
				
				reader = new Scanner(new File("src/resources/C-small-attempt0.in"));
				String nextline = reader.nextLine();
				noLines = new Integer(nextline);
				System.out.println(noLines);
				fstream = new FileWriter("out.txt");
				out = new BufferedWriter(fstream);
				
				process();
				out.close();
				
			}
			catch (Exception e) {
				// TODO: handle exception
			}
	}
	 public void process() throws IOException
	 {
		 while (reader.hasNext()) 
		{
			 	value=0;
			 	nextline = reader.nextLine();
			 	System.out.println("Case #"+(lineIndex)+": ");
	            out.write("Case #"+(lineIndex++)+": ");
	            StringTokenizer allwords = new StringTokenizer(nextline);
	            intA= new Integer(allwords.nextToken());
	            intB= new Integer(allwords.nextToken());
	            System.out.println(intA+"    "+intB);
	            
	            int n,m=0;
	            for(n=intA;n<=intB;n++)
	            {
	            	System.out.println(n+"    "+m);
	            	String ns=""+n;
	            	
	            	for(int i=1;i<=ns.length();i++)
	            	{
	            		//System.out.println(i);
	            		String S2=ns.substring(ns.length()-i);
	            		
	            		if(S2.charAt(0)=='0')
	            			continue;
	            		String S1=ns.substring(0,ns.length()-i);
	            		
	            		String ms=S2+S1;
	            		m=new Integer(ms);
	            		//System.out.println(isValid(n, m));
	            		if(isValid(n, m))
	            		{
	            			value++;
	            		}
	            		
	            	}
	            }
	            out.write(value+"\n");
	            

	       }
	 }
	 
	public static void main(String []args)
	{
		G2 obj=new G2();
		obj.initiateFiles();
		
		
		
	}

}
