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));
	}
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package codejam;
import java.io.*;
/**
 *
 * @author Nah-Abiah
 */
public class recycledNumbers {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try{
            FileInputStream fstream = new FileInputStream("C-small-attempt1.in");
            
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            
            int testCount = 0;
            int caseCount = 1;
            String writeFile = "";
            while ((strLine = br.readLine()) != null)   {
                if(testCount == 0){
                    testCount = Integer.parseInt(strLine);
                } 
                else{                    
                    String[] ints = strLine.split(" ");
                    int n = Integer.parseInt(ints[0]);
                    int limit = Integer.parseInt(ints[1]);                    
                    int num = 0;
                    if(ints[0].length() != 1){
                        while (n < limit){
                            int count = 1;
                            
                            while(count < ints[0].length()){
                                String m = String.valueOf(n).substring(count)+String.valueOf(n).substring(0, count);
                                if((n<Integer.parseInt(m)) && (Integer.parseInt(m)<= limit)){
                                    num++;
                                }
                                count++;
                            }
                            n++;
                        }
                    }
                    writeFile += "Case #"+caseCount+": "+num+"\r\n";
                    caseCount++;
                }
            }
            //Close the input stream
            in.close();
            
            try{
                // Create file 
                FileWriter filestream = new FileWriter("output.txt");
                BufferedWriter out = new BufferedWriter(filestream);
                out.write(writeFile);
                //Close the output stream
                out.close();
            }
            catch (Exception e){//Catch exception if any
                System.err.println("Error: " + e.getMessage());
            }
        }
        catch (IOException | NumberFormatException e){//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
    }
}
