
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;

public class Recycle
{
	public static void main(String[] args)
	{
/*		Set<Integer> perms = getPermutations(123456);
		
		for(Integer i: perms)
			System.out.println(i);*/
	
		try
		{
			Scanner s = new Scanner(new File("recycle.in"));
			BufferedWriter w = new BufferedWriter(new FileWriter(new File("recycle.out")));
			int numCases = s.nextInt();
			s.nextLine();
			
			for(int n = 1;n <= numCases; n++)
			{
				int A = s.nextInt();
				int B = s.nextInt();
				int count = 0;
				for(int k = A; k <= B; k++)
				{
					count += getNumPairs(k, B);
				}
				
				w.write("Case #" + n + ": " + count + "\n");
			}
			
			w.flush();
			w.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public static int getNumPairs(int n, int B)
	{
		Set<Integer> possibles = getPermutations(n);
		int count = 0;
		for(Integer i : possibles)
			if(i > n && i <= B)
				count++;
		return count;
	}
	
	public static Set<Integer> getPermutations(int n)
	{
		Set<Integer> perms = new TreeSet<Integer>();
		char[] digits = String.valueOf(n).toCharArray();
		
		for(int firstPos = 1; firstPos < digits.length; firstPos++)
		{
			String toBuild = "";
			for(int k = 0; k < digits.length; k++)
				toBuild += digits[(firstPos + k) % digits.length];
			perms.add(Integer.parseInt(toBuild));
		}
		return perms;
	}
	

}
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class main {

	public static void main(String[] args) {
		// inputãã¡ã¤ã«ãèª­ã¿è¾¼ã¿
		BufferedReader bufferReader = null;
		String str = "";
		try {
			bufferReader = new BufferedReader(new InputStreamReader(
					new FileInputStream("/Users/yago/Documents/in.txt"),
					"UTF-8"));
			// ä¸è¡ãã¤èª­ã¿è¾¼ã¿
			int probs = 0;
			while ((str = bufferReader.readLine()) != null) {
				if (str.length() > 2) {
					probs++;
					calc(str, probs);
				}
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		} finally {
			try {
				if (bufferReader != null) {
					bufferReader.close();
				}
			} catch (Exception e) {
			}
		}
	}

	private static void calc(String str, int probNum) {
		Integer n1, n2, ansCnt = 0;
		String[] strAry = str.split(" ");
		n1 = Integer.valueOf(strAry[0]);
		n2 = Integer.valueOf(strAry[1]);
		for (int i = n1; i <= n2; i++) {
			for (int j = i + 1; j <= n2; j++) {
				if(String.valueOf(j).length() == 1)
					break;
				if (String.valueOf(j).length() == 2) {
					if (String.valueOf(j).charAt(0) == String.valueOf(i)
							.charAt(1)
							&& String.valueOf(j).charAt(1) == String.valueOf(i)
									.charAt(0))
						ansCnt++;
				} else if ((String.valueOf(j).charAt(0) == String.valueOf(i)
						.charAt(1)
						&& String.valueOf(j).charAt(1) == String.valueOf(i)
								.charAt(2) && String.valueOf(j).charAt(2) == String
						.valueOf(i).charAt(0))
						|| String.valueOf(j).charAt(0) == String.valueOf(i)
								.charAt(2)
						&& String.valueOf(j).charAt(1) == String.valueOf(i)
								.charAt(0)
						&& String.valueOf(j).charAt(2) == String.valueOf(i)
								.charAt(1)) {
					ansCnt++;
				}
			}
		}

		System.out.println("Case #" + probNum + ": " + ansCnt);
	}
}