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

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;

public class ProblemCC {

	/**
	 * @param args
	 * @throws FileNotFoundException
	 */
	public static boolean check(String s) {
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.charAt(i) != s.charAt(i + 1))
				return true;
		}
		return false;
	}

	public static void main(String[] args) throws FileNotFoundException {
		Scanner in = new Scanner(new FileReader("C.in"));
		PrintWriter out = new PrintWriter("Clarge.out");
		int num = in.nextInt();
		for (int CASE = 1; CASE <= num; CASE++) {
			int a = in.nextInt();
			int b = in.nextInt();
			HashSet<String> hs = new HashSet<String>();
			for (int i = a; i <= b; i++) {
				String s = i + "";
				if (check(s) && s.length() > 1) {
					for (int k = s.length() - 2, j = 0; k >= 0 && j < s.length() - 1; j++, k--) {
						String newS = s.substring(k + 1) + s.substring(0, k + 1);
						int newInt = Integer.parseInt(newS);
						if (newInt <= b && i < newInt && s.length() == (newInt + "").length() && !newS.equals(s)) {
							if (i < Integer.parseInt(newS))
								hs.add(i + " " + newS);
							else
								hs.add(newS + " " + i);
						}
					}
				}
			}
			out.println("Case #" + CASE + ": " + hs.size());
		}
		out.close();
	}
}
