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();
	}

}

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class RecycledNumbers {

	private long low;
	private long high;
	private Map<Long, Boolean> map = new HashMap<Long, Boolean>();
	private int recycycled = 0;

	public static void main(String[] args) throws NumberFormatException,
			IOException {

		File file = new File("C:\\Users\\xebia\\Downloads\\C-large.in");

		FileInputStream fis = new FileInputStream(file);
		DataInputStream in = new DataInputStream(fis);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		int numberOfTestCases = new Integer(br.readLine());
		for (int j = 0; j < numberOfTestCases; j++) {

			RecycledNumbers re = new RecycledNumbers();
			String[] strings = br.readLine().split(" ");
			String s = strings[0];
			String s2 = strings[1];
			long high = new Long(s2);
			long low = new Long(s);
			int numberOfDigits = s.length();
			for (long i = low; i <= high; i++) {
				int roundOffFigure = 1;
				for (int k = 0; k < numberOfDigits - 1; k++) {
					roundOffFigure = roundOffFigure * 10;
					long lastDigit = (long) (i % roundOffFigure);
					String str = "" + lastDigit;

					if (str.length() == k + 1) {

						long startingCombination = (long) (i / roundOffFigure);
						if (lastDigit == 0) {
							continue;
						}
						long number = (long) (lastDigit
								* (Math.pow(10, numberOfDigits - str.length())) + startingCombination);

						if (number >= low && number <= high) {
							if (number != i) {
								Boolean bool = re.map.get(number * i);
								if (bool == null) {
									re.map.put(number * i, true);
									re.recycycled++;
								}

							}
						}
					}
				}

			}
			System.out.println("Case #" + (j + 1) + ": " + re.recycycled);
		}
	}

	public void setLow(long low) {
		this.low = low;
	}

	public long getLow() {
		return low;
	}

	public void setHigh(long high) {
		this.high = high;
	}

	public long getHigh() {
		return high;
	}

	public void setRecycycled(int recycycled) {
		this.recycycled = recycycled;
	}

	public int getRecycycled() {
		return recycycled;
	}

}
