/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gcj;

import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author daniele
 */
public class GCJ_C {
    
    public static void main(String[] args) throws Exception{
        
        
        
        Scanner in = new Scanner(new File(args[0]));
        FileWriter out = new FileWriter("/home/daniele/Scrivania/Output");
        

        int prove=in.nextInt();
        int min,max;
        int cifre;
        int cifreaus;
        String temp;
        int aus;
        int count=0;
        ArrayList<Integer> vals = new ArrayList<Integer>();
        int jcount=0;
        ArrayList<Integer> perm = new ArrayList<Integer>();
        
        out.write("");
        out.flush();
        
        for(int i=1;i<=prove;i++){
            
            out.append("Case #" +i+": ");out.flush();
            
            min=in.nextInt();
            max=in.nextInt();
            
            for(int j=min;j<=max;j++){
               if(!vals.contains(j)){
                    temp=""+j;
                    cifre=temp.length();
                    aus=j;
                    perm.add(j);
                    for(int k=1;k<cifre;k++){
                        aus=rotateOnce(aus);
                        temp=""+aus;
                        cifreaus=temp.length();//elusione zeri iniziali
                        if(aus>=min && aus<=max && aus!=j && cifreaus==cifre && nobody(vals,perm)){ 
                            perm.add(aus);
                            jcount ++;
                            
                        }
                        
                    }
                    while(jcount>0){count+=jcount; jcount--;}
                    vals.addAll(perm);
                    perm= new ArrayList<Integer>();
                    
                }
            }
            out.append(count+"\n");out.flush();
            count=0;
            vals= new ArrayList<Integer>();
        }
        
        
        
    }
        static public int rotateOnce(int n){
            String s=""+n;
            if(s.length()>1){
                s=s.charAt(s.length()-1) + s.substring(0,s.length()-1);
                n=Integer.parseInt(s);
            }
            return n;
        }    
        
        static public boolean nobody(ArrayList<Integer> v,ArrayList<Integer> a){;
            for(int i=0;i<a.size();i++)
                if(v.contains(a.get(i))) return false;
            return true;
        } 
    
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


public class RecycledNumbers {
	public static void main(String[] args) {
		RecycledNumbers recycled = new RecycledNumbers();
		recycled.read_input_file();
		/*if(recycled.check_if_the_number_is_a_recycled_pair("23451", "34512", "12345")) {
			number_of_recycled_pairs ++;
			System.out.println(number_of_recycled_pairs);
		}*/
	}
	
	public boolean check_if_the_number_is_a_recycled_pair(String first_number, String second_number, String original_number) {
		if (original_number.equals(first_number)) {
			return false;
		} else if(first_number.equals(second_number)) {
			return true;
		} else {
			return check_if_the_number_is_a_recycled_pair((first_number.substring(1) + first_number.charAt(0)), second_number, original_number);
		}
	}
	public void read_input_file() {
		try {
			BufferedReader rd = new BufferedReader(new FileReader("C-small-attempt2.in"));
			
			FileWriter fstream = new FileWriter("output.txt");
			BufferedWriter out = new BufferedWriter(fstream);
			
			T = Integer.parseInt(rd.readLine());
			System.out.println(T);
			while (true) {
				String A_and_B = rd.readLine();
				System.out.println(A_and_B);
				if (A_and_B == null) {
					break;
				}
				parse_line(A_and_B, out);
				number_of_recycled_pairs = 0;
			}
			out.close();
			rd.close();
		} catch (IOException ex) {
			System.out.println("file not found");
		}
	}
	
	public void parse_line(String A_and_B, BufferedWriter out) {
		String A = A_and_B.substring(0, A_and_B.indexOf(" "));
		String B = A_and_B.substring(A_and_B.indexOf(" ") + 1);
		
		for (Integer i = Integer.parseInt(A); i < Integer.parseInt(B); i++) {
			for (Integer j = i + 1; j <= Integer.parseInt(B); j++) {
				String original_number = i.toString();
				String first_number = original_number.substring(1) + original_number.charAt(0);
				String second_number = j.toString();
				if (check_if_the_number_is_a_recycled_pair(first_number, second_number, original_number)) {
					number_of_recycled_pairs ++;
				}
			}
		}
		Save_line_to_output_file(out);
		
	}
	
	public void Save_line_to_output_file(BufferedWriter out) {
		try{
			  // Create file 
			  out.write("Case #" + (counter + 1) + ": " + number_of_recycled_pairs);
			  out.newLine();
			  counter ++;
			  //Close the output stream
			} catch (Exception e) {//Catch exception if any
			  System.err.println("Error: " + e.getMessage());
		 }
	}
	int counter = 0;
	int T= 0;
	static int number_of_recycled_pairs = 0;
}
