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.util.*;
import java.io.*;

class Node implements Comparable{
	int x, y;
	public Node(){}
	public Node(int a, int b){
		x = a; y = b;
	}
	public boolean equals(Object key){
		Node tmp = (Node)key;
		if(x==tmp.x && y==tmp.y)  return  true;
		else  return  false;
	}
	public int compareTo(Object key){
		Node tmp = (Node)key;
		if(x == tmp.x)  return  y-tmp.y;
		else  return  x-tmp.x;
	}
}

public class C{
	Set hash = new TreeSet<Node>();
	void Cal(int A, int B, int n, PrintWriter cout){
		int ct = 0;
		String sn = Integer.valueOf(n).toString();
		for(int i = 1; i < sn.length(); i++){
			String sm = sn.substring(i) + sn.substring(0, i);
			int m = Integer.parseInt(sm);
			Node tmp = new Node(n, m);
			if(m>n && m<=B && !hash.contains(tmp))
				hash.add(tmp);
			//System.out.println(hash.size());
		}
	}
	void solve() throws FileNotFoundException{
		File fin = new File("data.in");
		File fout = new File("data.out");
		Scanner cin = new Scanner(fin);
		PrintWriter cout = new PrintWriter(fout);
		
		int T, A, B;
		T = cin.nextInt();
		for(int k = 1; k <= T; k++){
			A = cin.nextInt(); B = cin.nextInt();
			hash.clear();
			for(int i = A; i < B; i++)
				Cal(A, B, i, cout);
			cout.printf("Case #%d: %d\n", k, hash.size());
		}
		
		cout.flush();
	}
	public static void main(String [] args) throws Exception{
		C test = new C();
		test.solve();
	}
}












