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 java.io.*;
import java.util.*;

class Recycled
{
	int n;
	int m;

	Recycled (int a, int b)
	{
		n=a;
		m=b;
	}

	boolean isEqual(int a, int b)
	{
		if (n == a && m == b)
			return true;
		else
			return false;
	}
}

class C
{
	public static void main(String args[]) throws FileNotFoundException
	{
		Scanner in = new Scanner(new File(args[0]));

		int t;

		t = Integer.parseInt(in.nextLine());

		for (int i=0; i<t; i++)
		{
			int a = in.nextInt();
			int b = in.nextInt();
			int s = 0;
			ArrayList<Recycled> recs = new ArrayList<Recycled>();

			for (int n=a; n<b; n++)
			{
				String x = String.valueOf(n);
				String y = new String();
				for (int j=0; j<x.length()-1; j++)
				{
					y = x.substring(j+1) + x.substring(0,j+1);
					int m = Integer.parseInt(y);
					if ( n < m && m <= b)
					{
						boolean distinct = true;
						for (Recycled rec: recs)
						{
							if (rec.isEqual(n,m))
							{
								distinct = false;
								break;
							}	
						}

						if (distinct)
						{
							recs.add(new Recycled(n,m));
							s++;
						}
					}
				}

			}
			
			System.out.println("Case #" + (i+1) + ": " + s);
		}

	}
}
