package fixjava;

public class StringUtils {

	/** Repeat the given string the requested number of times. */
	public static String repeat(String str, int numTimes) {
		StringBuilder buf = new StringBuilder(Math.max(0, str.length() * numTimes));
		for (int i = 0; i < numTimes; i++)
			buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the left hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padLeft(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(padChar);
		for (int i = 1, mi = bufSize - str.length(); i < mi; i++)
			buf.append(padChar);
		buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the right hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padRight(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(str);
		buf.append(padChar);
		while (buf.length() < bufSize)
			buf.append(padChar);
		return buf.toString();
	}

	/** Intern all strings in an array, skipping null elements. */
	public static String[] intern(String[] arr) {
		for (int i = 0; i < arr.length; i++)
			arr[i] = arr[i].intern();
		return arr;
	}

	/** Intern a string, ignoring null */
	public static String intern(String str) {
		return str == null ? null : str.intern();
	}

}

/*
ID: 14vikra1
LANG: JAVA
TASK: recycled
*/
import java.io.*;
import java.util.*;

class recycled {
	public static void main (String [] args) throws IOException {
		long start = System.currentTimeMillis();
		BufferedReader br = new BufferedReader(new FileReader("recycled.in"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("recycled.out")));
		int T = Integer.parseInt(br.readLine());
		for (int i = 0; i < T; i++) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			int A = Integer.parseInt(st.nextToken());
			int B = Integer.parseInt(st.nextToken());
			int pairs = 0;
			for (int j = A; j < B; j++) {
				pairs += checkPairsNew(j, A, B);
			}
			out.println("Case #" + (i+1) + ": " + pairs);
		}
		long end = System.currentTimeMillis();
		System.out.println(end-start);
		out.close();
		System.exit(0);        
	}
	public static int checkPairsNew(int num, int A, int B) {
		int numpairs = 0;
		String Bs = Integer.toString(B);
		String nums = Integer.toString(num);
		int size = Bs.length();
		ArrayList used = new ArrayList();
		for (int i = 1; i < size; i++) {
			String moves = nums.substring(size-i,size);
			String tests = nums.substring(0,i);
			String testBs = Bs.substring(0,i);
			int move = Integer.parseInt(moves);
			int test = Integer.parseInt(tests);
			int testB = Integer.parseInt(testBs);
			//System.out.println(move + " " + test + " " + testB + " " + num);
			if (move >= test && move <= testB) {
				String newnums = nums.substring(0, size-i);
				newnums = moves + newnums;
				int newnum = Integer.parseInt(newnums);
				//System.out.println(move + " " + test + " " + testB + " " + num + " " + newnum);
				if (newnum > num && newnum <= B && !used.contains(newnum)) {
					numpairs++;
					used.add(newnum);
				}
			}
		}
		return numpairs;
	}
	public static int checkPairs(int num, int A, int B, int size) {
		int numpairs = 0;
		ArrayList used = new ArrayList();
		for (int i = 1; i < size; i++) {
			int move = (int)(num%Math.pow(10, i));
			int test = (int)((num)/Math.pow(10,size-i+1));
			int testB = (int)((B)/Math.pow(10,size-i+1));
			if (move >= test && move <= testB) {
				int newnum = (int)((num - move)/Math.pow(10,i));
				newnum = newnum + move*(int)(Math.pow(10,size-i));
				if (newnum > num && newnum <= B && !used.contains(newnum)) {
					numpairs++;
					used.add(newnum);
				}
			}
		}
		return numpairs;
	}
}

