import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

import java.io.*;
import java.util.*;
public class RecycledNumbers
{
	public static void main(String args[]) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());
		int[][] ab = new int[T][2];
		StringTokenizer st = null;
		for (int i=0; i<T; i++)
		{
			st = new StringTokenizer(br.readLine());
			ab[i][0]=Integer.parseInt(st.nextToken());
			ab[i][1]=Integer.parseInt(st.nextToken());
		}
		for (int i=0; i<T; i++)
		{
			System.out.print("Case #"+(i+1)+": ");
			int c=0;
			int dig = (int)Math.log10(ab[i][0]);
			for (int j=ab[i][0]; j<=ab[i][1]; j++)
			{
				int newno=j;
				do
				{
					int last = newno%10;
					newno/=10;
					newno = (int) (last*Math.pow(10,dig) + newno);
					if (newno == j)
						break;
					if (newno <= ab[i][1] && newno >= ab[i][0] && j<newno)
						c++;
				} while (true);
			}
			System.out.println(c);
		}
	}
}
