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.util.Scanner;


public class C_RecycledNumbers {

	static int[] bases = {0, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
	static int digits(int value) {
		int i = 0;
		for (; i < bases.length && value >= bases[i]; i++);
		return i;
	}
	
	static int shift(int value, int len) {
		int last = value % 10;
		return (int)(Math.pow(10, len - 1)) * last + (value / 10);
	}
	
	
	static int countRecycled(int value, int B) {
		int shifted = value;
		int len = digits(value);
		int[] cache = new int[len];
		int ck = 0;
out:	for (int i = 0; i < len - 1; i++) {
			shifted = shift(shifted, len);
			
			if (shifted > value && shifted <= B) {
				for (int j = 0; cache[j] != 0; j++)
					if (cache[j] == shifted)
						continue out;	
				//System.out.println("n=" + value + ", m=" + shifted);
				cache[ck++] = shifted;
			}
		}
		return ck;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		/*int A = 1;
		int B = 2000000;
		int count = 0;
		for (int val = A; val <= B; val++) {
			count += countRecycled(val, B);
		}
		System.out.println(count);
		/**/
		
		Scanner scan = new Scanner(System.in);
		int test = scan.nextInt();
		for (int t = 1; t <= test; t++) {
			int A = scan.nextInt();
			int B = scan.nextInt();
			int count = 0;
			for (int val = A; val <= B; val++) {
				count += countRecycled(val, B);
			}
			System.out.println("Case #" + t + ": " + count);
		}/**/
	}
}
