import java.util.*;
import java.io.*;

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package codejam2012;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author acer
 */
public class C {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        // TODO code application logic here
        FileInputStream input = new FileInputStream("input.txt");
        DataInputStream in = new DataInputStream(input);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));

        FileOutputStream output = new FileOutputStream("output.txt");

        int T = Integer.parseInt(br.readLine());
        int A, B;

        for (int i = 0; i < T; i++) {
            String[] temp = br.readLine().split(" ");
            A = Integer.parseInt(temp[0]);
            if (A < 12) {
                A = 12;
            }
            B = Integer.parseInt(temp[1]);
            if (B < A) {
                output.write(("Case #" + (i + 1) + ": " + "0" + "\n").getBytes());
                continue;
            }
            int j = A, count = 0;

            while (j <= B) {
                String thisNo = new Integer(j).toString();
                Set<Integer> intSet = new HashSet<Integer>();
                for (int k = 1; k < thisNo.length(); k++) {
                    int newNo = Integer.parseInt(thisNo.substring(thisNo.length() - k) + thisNo.substring(0, thisNo.length() - k));
                    if (newNo <= B && Integer.parseInt(thisNo) < newNo && !intSet.contains(newNo)) {
                        count++;
                        intSet.add(newNo);
                    }
                }
                j++;
            }
            output.write(("Case #" + (i + 1) + ": " + count + "\n").getBytes());
        }
    }
}
