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.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public class R1P3 {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {

		BufferedReader in = new BufferedReader(new FileReader("C-large.in"));
		BufferedWriter bw = new BufferedWriter(new FileWriter("large3.out"));
		String inLine;
		int t = Integer.parseInt(in.readLine());
		int counter = 0;
		while ((inLine = in.readLine()) != null) {
			counter++;
			String[] toks = inLine.split(" ");
			long beg = Long.parseLong(toks[0]);
			long end = Long.parseLong(toks[1]);
			long c = 0;
			for (long i = beg; i < end; i++) {
				c += rotateNumber(i, end);
			}
			System.out.println("Case #" + counter + ": " + c);
			bw.write("Case #" + counter + ": " + c);
			bw.newLine();
		}
		in.close();
		bw.close();
	}

	public static long rotateNumber(long number, long end) {
		long start = number;
		int numdigits = (int) Math.log10((double) number); // would return
															// numdigits - 1
		int multiplier = (int) Math.pow(10.0, (double) numdigits);
		long counter = 0;
		while (true) {
			long q = number / 10;
			long r = number % 10;
			number = number / 10;
			number = number + multiplier * r;
			if (start < number && number <= end)
				counter++;
			if (number == start)
				break;
		}
		return counter;
	}

}
