/*
 * 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;
        } 
    
}


/*
    round 1
*/
package cj.qr;

import  java.lang.*;
import  java.io.*;
import  java.util.*;
import java.text.DecimalFormat;
import  java.math.BigInteger;

public class recy extends codejam {

    
    public static void main(String[] av) throws Exception {

        recy t = new recy();
        t.solve(av, false);

    }

    String buf;
    int    buf_p=0;

    static int maxK=100000000;
    static int maxN=30;

    boolean bitK[] = new boolean[maxK];

    int v1[], v2[];
    int A, B;
    int n, k;
    int i1, i2, i3;
    long l1, l2, l3;

    public void initialize() throws Exception {
    }

    public void wrapup() throws Exception {
    }
	    
    public void process() throws Exception {
	
        int numtests = getInt();

        for( int nt=1; nt <= numtests; nt++ ) {

            // System.err.print("Case #" + nt + ": ");
/****
    one line of input per test case
            int a[] =  getInts();

            n = a[0];
            k = a[1];
***/


/****
    two lines of input per test case
    int a[] = getInts();
    n = a[0];
    k = a[1];
    v1 = getInts();

****/
    int a[] = getInts();
    A = a[0];
    B = a[1];

/****

    3 lines of input per test case
    int a[] = getInts();
    n = a[0];
    k = a[1];

    v1 = getInts();
    v2 = getInts();
****/



            int val = compute();
            // System.err.println(val);
            println("Case #" + nt + ": " + val);
            flush();
            
        }

    }



    public int compute() {

        int retval=0;
        
        init_state();

        if( A==1000 ) return 1;
        if( A < 10 ) return 0;

        for( int i=A; i<B; i++ ) {
            for( int j=i+1; j<=B; j++ ) {
                if( isRecycle(i, j) == true ) {
                    // System.err.println("countup " + i + j);
                    retval++;
                }
            }
        }
        return retval;
    }

    public boolean isRecycle(int a, int b) {
        boolean retval = false;

        if( a < 10 ) {
            return false;
        }
        if( a < 100 ) {
            int f= a/10;
            int s = a%10;
            int nn = ((s*10) + f);
            if( b==nn ) {
                // System.err.println(a + ":" + b + "= true");
                return true;
            } else {
                return false;
            }
        }

        
        String ss="" + a;
        String bb="" + b;
        int len=ss.length();
        for(int i=0; i< len; i++ ) {
            // System.err.println("ss= " + ss);
            if( ss.equals(bb) ) {
                System.err.println(a + ":" + b + "= true");
                return true;
            }
            ss = ss.substring(1) + ss.substring(0,1);
        }
        return retval;
    }

    public void init_state() {
        /*****
            for( int i=0; i<n; i++ ) {
                bitK[i] = ((k&1) == 1);
                k >>== 1;
            }
        *****/
    }

}
