import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

// Recycled Numbers
// https://code.google.com/codejam/contest/1460488/dashboard#s=p2

public class C {

	private static String process(Scanner in) {
		int A = in.nextInt();
		int B = in.nextInt();
		int res = 0;
		int len = Integer.toString(A).length();
		for(int n = A; n < B; n++) {
			String str = Integer.toString(n);
			TreeSet<Integer> set = new TreeSet<Integer>();
			for(int i = 1; i < len; i++) {
				int m = Integer.parseInt(str.substring(i, len) + str.substring(0, i));
				if ( m > n && m <= B && ! set.contains(m) ) {
					set.add(m);
					res++;
				}
			}
		}
		return Integer.toString(res);
	}

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in.available() > 0 ? System.in : 
			new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + ".practice.in"));
		int T = in.nextInt();
		for(int i = 1; i <= T; i++) 
			System.out.format("Case #%d: %s\n", i, process(in));
	}
}

package googlecodejam2012_qualification;
/** 
 * @author neil
 */
import java.io.*;
import java.util.*;
public class NewMain {

    /**
     * @param args the command line arguments
     */
    static boolean recycle(int n,int m)
    {
        String N = Integer.toString(n);
        String M = Integer.toString(m);
        for(int i=1;i<N.length();i++)
        {
            N = N.substring(N.length()-1)+N.substring(0,N.length()-1);
            //System.out.println("checking "+N+" "+M);
            if(N.equals(M)) return true;
        }
        return false;
    }
    
    public static void main(String[] args) throws IOException
    {        
        //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));   
        BufferedReader in = new BufferedReader(new FileReader("./src/googlecodejam2012_qualification/io/C-small-input.in"));        
        BufferedWriter out = new BufferedWriter(new FileWriter("./src/googlecodejam2012_qualification/io/C-small-output.txt"));
        PrintStream ps = new PrintStream(System.out,true);
        StringTokenizer st;//st = new StringTokenizer(in.readLine()," ");
        int t = Integer.parseInt(in.readLine());
        int count=0,count1=0;
        while(count++<t)
        {
            st = new StringTokenizer(in.readLine()," ");
            int A = Integer.parseInt(st.nextToken());
            int B = Integer.parseInt(st.nextToken());

            count1=0;
            for(int i=A;i<=B;i++)
            {
                int m = i;
                for(int j=A;j<m;j++)
                {
                    int n = j;
                    if(Integer.toString(m).length()==(Integer.toString(n).length())&&recycle(n,m))
                    {
                        count1++;
                    }
                }
            }
            
            ps.println("Case #"+count+": "+count1);
            out.write("Case #"+count+": "+count1+"\n");
            out.flush();
        }                
    }
}
