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.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;


public class RecycledNumbers {


	public static void main(String[] args) throws IOException 
	{
		//BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("C-small-attempt0.in")));
		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("C-large.in")));
		//BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter out = new BufferedWriter(new FileWriter("RecycledNumbers.txt"));
		int cases = Integer.parseInt(reader.readLine());
		for(int i=1; i <= cases; i++)
		{
			String line = reader.readLine();
			int beg = Integer.parseInt(line.split(" ")[0]);
			int end = Integer.parseInt(line.split(" ")[1]);
			HashSet<Integer> h = new HashSet<Integer>();
			int count = 0;
			for(int j=beg; j<=end;j++) {
				String str = j+"";
				int c = 0;
				for(int m = str.length()-1; m>=0; m--) {
					str = str.substring(1) + str.charAt(0);
					int number = Integer.parseInt(str);
					if(number >= beg && number <= end && !h.contains(number)) {
						h.add(number);
						c++;
					}
				}
				count = count + ((c-1)*c)/2;
			}

			//out.write((p*3-2) + " " + (p*3-4) + "\n");
			System.out.print("Case #" + i+ ": " + count+"\n");
			out.write("Case #" + i+ ": " + count+"\n");
		}
		out.close();
	}



}


