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

package Happy;
import java.io.*;
import java.math.*;
import java.lang.*;
import java.util.*;
import java.util.Arrays.*;
import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.io.PrintWriter;
//import java.util.StringTokenizer;

/**
 *
 * @author ipoqi
 */
public class Happy {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Happy().haha();
    }

    public void haha() {
        BufferedReader in = null;
        BufferedWriter out = null;
        try{
            in = new BufferedReader(new FileReader("C-large.in"));
            out = new BufferedWriter(new FileWriter("LLL.out"));
            int T = Integer.parseInt(in.readLine());
            System.out.println("T="+T);

            //LinkedList<Integer> mm = new LinkedList<Integer>();
            //mm.add(new LinkedList<Integer>());
           //int[][] mm;
           //for(int ii=0;ii<mm.length;ii++){
           //     mm[0][ii] = 1;
           //}


            for(int i=0;i<T;i++){
                String[] line = in.readLine().split(" ");
                int A = Integer.parseInt(line[0]);
                int B = Integer.parseInt(line[1]);
                //System.out.print(" A = "+A+"\n");
                //System.out.print(" B = "+B+"\n");

                int ans = 0;

                
                for(int j=A;j<B;j++){
                    int n=j;
                    if(n>=10){
                        String N = Integer.toString(n);
                        int nlen = N.length();
                        List<Integer> oks = new ArrayList<Integer>();
                        for(int k=0;k<nlen-1;k++){
                            String M = "";
                            for(int kk=1;kk<=nlen;kk++){
                                 M = M + N.charAt((k+kk)%nlen);
                            }
                            int m = Integer.parseInt(M);
                            //System.out.print(" N = "+N+"\n");
                            //System.out.print(" M = "+M+"\n");

                            if(m>n && m<=B) {
                                boolean isNewOne = true;
                                for(int kkk=0;kkk<oks.size();kkk++){
                                    //System.out.print(" KKK = "+oks.get(kkk)+"\n");
                                    if(m==oks.get(kkk)){
                                        isNewOne = false;
                                    }
                                }
                                if(isNewOne){
                                    //System.out.print(" N = "+N+"\n");
                                    //System.out.print(" M = "+M+"\n");
                                    oks.add(m);
                                    ans++;
                                }
                            }
                        }
                    }
                }
                out.write("Case #"+(i+1)+": "+ans+"\n");
                System.out.print("Case #"+(i+1)+": "+ans+"\n");
            }
            in.close();
            out.close();
        }catch(Exception e){
            e.printStackTrace();
            try{
                in.close();
                out.close();
            }catch(Exception e1){
                e1.printStackTrace();
            }
        }
        System.out.print("YES!\n");
    }

}
import java.io.*;
import java.util.*;
import java.util.ArrayList;





public class CodeJamProblem implements Runnable {
//Problem C
	public boolean InRisultati(ArrayList<String> array, String controllo) {
		for(int i =0; i<array.size();i++) {
			if(array.get(i)==controllo) {
				System.out.println("Risutlato gia contato");
				return true;
			}
		}
		return false;
	}
	
	public int getRisultato(int[] items, int caso) {
		// n=6 s=2 p=8 29 20 8 18 18 21
		int vincitori = 0;
		
		Arrays.sort(items);
		int A = items[0];
	    int B = items[1];
	    int current_n =-1;
	    int current_m =-1;
	    // 1 digit, no solution:
	    if (A<10 && B<10)
	    {
	      return 0;
	    }
	    int[] range = new int[B-A+1];
	    //System.out.println("Range LEN:"+ range.length);
	    for(int i=0;i<range.length;i++) {
	    	range[i] = i+A;
	    	//if(caso==3)
	    	//	System.out.print(range[i]+ " ");
	    }
	    int count = 0;
	    
	    ArrayList<String> risultati = new ArrayList<String>();
	    
	    if(caso==3)
	    System.out.println(" ");
	    for (int i = 0; i < range.length; i++)
	    {
	      current_n = range[i];
	      current_m = range[i];
	      String rot_m = ""+current_m;
	      //if(caso==3)
	    	//  System.out.println("Numero: " +current_m);
	      
	      int len = (range[i]+"").length();
	      for (int j = 0; j < len; j++)
	      {
	    	  if(caso==3)
	    		  System.out.print(" " + rot_m.substring(rot_m.length()-1) + 
	    			  rot_m.substring(0,len-1));
	    	  rot_m = (   
	    			  rot_m.substring(rot_m.length()-1) + 
	    			  rot_m.substring(0,len-1)
	    			  );
	        // A ² n < m ² B
	        if (Integer.parseInt(rot_m) <= B && Integer.parseInt(rot_m) > current_n && Integer.parseInt(rot_m) >= A)
	        {
	        	//if(InRisultati(risultati,current_n+rot_m)==false) {
	        	//	risultati.add(current_n+rot_m);
	        		vincitori++;
	        		
	        	//}
	        	
	        }
	      }
	      if(caso==3)
	    	  System.out.println(" ");
	    }
	    if(caso==3)
	    	System.out.println("Winner :"+ vincitori);
		return vincitori;
	}
	
	
	public void solve() throws IOException {
		String test = "small";
		//String test = "large";
		Scanner in = new Scanner(new File("C-large.in")).useDelimiter(System.getProperty("line.separator")); 
        PrintWriter out = new PrintWriter(new File("C-large.out"));
        
        int lineNum = 0;
        int testNum = 0;
        int totalTests = 0;
        int[] points = new int[1];
        while (in.hasNext()) {
        	String currentLine = in.next();
        	if(lineNum ==0 ) {
        		//Do Nothing!
        		totalTests = Integer.parseInt(currentLine);
        		lineNum++;
        		continue;
        	}
        	if(lineNum>0) {
        		String[] x = currentLine.split(" ");
        		points = new int[x.length];
                for(int i = 0;i<x.length;i++) {
               		points[i] = Integer.parseInt(x[i]);
                }
        		int risultato = getRisultato(points, testNum);
        		//if(testNum==3)
        		System.out.println("Case #"+(testNum+1)+": "+ risultato);
        		out.println("Case #"+(testNum+1)+": "+ risultato);
        		testNum++;
        	}
            lineNum++;
        }
        in.close();
        out.close();
        
		
	}
	public void run() {
        try {
            solve();
        } catch (IOException e) {
            System.exit(1);
        }
    }

    public static void main(String[] s) {
        new Thread(new CodeJamProblem()).start();
    }
	
	
	
}
