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 Recycled {
	/*
	private static boolean areTwoMirrors(int n, int m, int A, int B) {
		if (A > n || n >= m || m > B) return false;
		
		String mStr = Integer.toString(m);
		String nStr = Integer.toString(n);
		if (mStr.charAt(0) == '0' || nStr.charAt(0)=='0') return false;
		if (mStr.length() != nStr.length()) return false;
		for (int i=1; i < nStr.length(); i++) {
			nStr = nStr.substring(1) + nStr.charAt(0);
			if (nStr.equals(mStr)) return true;
		}
		return false;
	}*/
	static int[] powersOfTen = new int[7];
	private static int process(int A, int B) {
		//boolean[] hasVisited = new boolean[B+1];
		int numDigits = Integer.toString(A).length();
		int count = 0;
		for (int i = A; i < B; i++) {
			int num = i;
			for (int start = 1; start < numDigits; start++) {
				int firstDigit = num/powersOfTen[numDigits-1];
				num -= firstDigit*powersOfTen[numDigits-1];
				num *= 10;
				num += firstDigit;
				if (num <= B && num > i) {
					//if (!areTwoMirrors(i,num,A,B)) System.out.println("Jlfwje");
					//System.out.println(i+" "+num);
					count++;
				}
			}
		}
		return count;
	}
	public static void main(String[] args) {
		int currPower = 1;
		for (int i=0; i < powersOfTen.length; i++) {
			powersOfTen[i] = currPower;
			currPower *= 10;
		}
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		for (int i=0; i < T; i++) {
			int A = in.nextInt();
			int B = in.nextInt();
			System.out.println("Case #"+(i+1)+": "+process(A,B));
		}
		
		//System.out.println(process(A,B));
	}
}
