import java.util.*;
import java.io.*;

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
//input file must be in.txt in this directory
//output file will be out.txt

import java.io.*;
import java.util.*;
public class C
{
	public static Scanner in;
	public static PrintStream out;
	public static void main(String [] args) throws Throwable
	{
		in = new Scanner(new File("in.txt"));
		int cases = in.nextInt();
		in.nextLine();
		out = new PrintStream(new File("out.txt"));
		for (int i = 1; i <= cases; i++)
		{
			out.print("Case #" + i + ": ");
			printResult();
			out.println();
		}
	}
	public static void printResult()
	{
		int a,b;
		a = in.nextInt();
		b = in.nextInt();
		int i = a;
		int firstDigit = 1;
		int numDigits = 0;
		while (i > 0)
		{
			i /= 10;
			firstDigit *= 10;
			numDigits++;
		}
		int [] alreadyDone = new int[numDigits];
		firstDigit /= 10;
		int cur,m;
		int tot = 0;
		boolean notDone;
		for (i = a; i < b; i++)
		{
			cur = i;
			for (int j = 1; j < numDigits; j++)
				alreadyDone[j] = -1;
			for (int j = 1; j < numDigits; j++)
			{
				m = cur % 10;
				cur = (cur / 10) + (m * firstDigit);
				if (cur > i && cur <= b)
				{
					notDone = true;
					for (int k = 1; k < j; k++)
					{
						if (alreadyDone[k] == cur)
						{
							notDone = false;
							break;
						}
					}
					if (notDone)
					{
						alreadyDone[j] = cur;
						tot++;
					}
				}
			}
		}
		out.print(tot);
	}
}
