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.FileReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;


public class RecycledNumbers {
	
	public static void main(String[] args) throws Exception {
		int i,j,k;
		int A, B;
		int L;
		String first, second, secondNoLeadingZeros;
		int s;
		HashSet<Integer> hs = new HashSet<Integer>();
		
		BufferedReader br = new BufferedReader(new FileReader("C-large.in"));
		PrintWriter out = new PrintWriter("C-large.out");
		StringTokenizer st;
		
		int T = Integer.parseInt(br.readLine());
		int res;
		
		for (k=1;k<=T;k++) {
			System.out.println(k+"/"+T);
			st = new StringTokenizer(br.readLine());
			A = Integer.parseInt(st.nextToken());
			B = Integer.parseInt(st.nextToken());
			L = Integer.toString(A).length();
			res = 0;
			
			for (i=A;i<=B;i++) {
				
				first = Integer.toString(i);
				hs.clear();
				hs.add(i);
				
				for (j=1;j<L;j++) {
					second = first.substring(j)+first.substring(0, j);
					s = Integer.parseInt(second);
					secondNoLeadingZeros = Integer.toString(s);
					if (secondNoLeadingZeros.length() == L) {
						if (( s >= A)&&(s <= B)) {
							if (hs.contains(s) == false) {
								hs.add(s);
								res++;
							}
						}
					}
				}
					
			}
			
			res /= 2;
			out.println("Case #"+k+": "+res);
			
		}
		
		out.close();
		
	}

}
