package qual;

import java.util.Scanner;

public class RecycledNumbers {

	public static void main(String[] args) {
		new RecycledNumbers().run();

	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int result = solve(A, B);
			System.out.printf("Case #%d: %d\n", t + 1, result);
		}
	}

	public int solve(int A, int B) {
		int result = 0;
		for (int i = A; i <= B; i++) {
			int dig = (int) Math.log10(A/*same as B*/) + 1;
			int aa = i;
			for (int d = 0; d < dig - 1; d++) {
				aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
				if (i == aa) {
					break;
				}
				if (i < aa && aa <= B) {
//					System.out.printf("(%d, %d) ", i, aa);
					result++;
				}
			}
		}
		return result;
	}

}

import javax.swing.*;
import java.util.Scanner;
import java.io.*;

class ProblemC
{
	public static void main (String []sdvv) throws IOException
	{
		int cases=0, A=0, B=0, total;
		String num;
		Scanner sc;
		PrintWriter es;
		try
		{
			sc = new Scanner(new File("Csmall.IN"));
			es = new PrintWriter(new BufferedWriter(new FileWriter("solutionC.txt")));
			cases=Integer.parseInt(sc.nextLine());
			for(int j=1;j<=cases;j++)
			{
				total=0;
				es.print("Case #"+j+": ");
				A=sc.nextInt();
				B=sc.nextInt();

				for(int n=A;n<B;n++)
				{
					for(int m=n+1;m<=B;m++)
					{
						if(checkRotation(n,m))
						{
							total++;
						}
					}
				}

				es.println(total);
			}
			es.close();
		}
		catch(FileNotFoundException error)
		{
			System.out.println("no se encuentra el archivo");
		}
		catch (EOFException e)
		{
		    System.out.println("Final de Stream");
		}

	}
	public static boolean checkRotation(int n, int m)
	{
		String num=Integer.toString(n);
		String ref=Integer.toString(m);
		if(num.length()==ref.length())
		{
			int l=num.length();
			String temp=num;
			for(int z=1;z<l;z++)
			{
				temp=temp.substring(1,l);
				temp+=num.charAt(z-1);
				if(temp.equals(ref))
					return true;
			}
		}
		return false;
	}
}