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.*;

public class P3L
{
    public static void main(String[] args) throws Exception
    {
        Scanner sc = new Scanner(new FileReader("input.txt"));
        PrintWriter pw = new PrintWriter(new FileWriter("output.txt"));
        
        int cases = Integer.parseInt(sc.nextLine());
        int c = 0;
        
        for (int i = 0; i < cases; i++)
        {
            long l = sc.nextLong(); // lower limit
            long u = sc.nextLong(); // upper limit
            c = 0;
            
            for(long j = l; j<= u; j++)
            {
                c += noOfCombos(j,l,u);
            }
            
            pw.println("Case #" + (i + 1) + ": " + c);
        }
        
        pw.close();
        sc.close();
    }
    
    static int noOfCombos(long x ,long l, long u) throws Exception
    {
        String s = (x+"");
        long n = 0;
        int c = 0;
        int d = s.length();
        String answers = "";
        
        for(int i = 1; i<d; i++)
        {
            boolean lz = s.charAt(i) == '0';
            if(!lz)
            {
                String s2 = s.substring(i) + s.substring(0,i);
                n = Long.valueOf(s2);
                if(n >= l && n <= u && n > x)
                {
                    if(answers.indexOf(s2) == -1)
                    {
                        answers += s2 + " ";
                        c++;
                    }
                }
            }
        }
        return c;
    }
}