/*
 * 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.util.HashSet;
import java.util.Set;


public class Problem3 {
	private static int getRecycledNumbersCount(int min, int max) {
		int numberOfDigits = getNumberOfDigits(min, max);
		int prefix;
		int suffix;
		int finalNumber;
		Set<String> pairs = new HashSet<String>();
		for (int i = min ; i < max; i++) {
			for (int j = 1; j<numberOfDigits; j++) {
				prefix = (int) (i % Math.pow(10, j) * Math.pow(10, numberOfDigits - j));
				suffix = (int) (i / Math.pow(10, j));
				finalNumber = prefix + suffix;
				
				if (isValid(finalNumber, i, min, max)) {
					pairs.add(i + " , " + finalNumber);
				}
				
			}
		}
		
		return pairs.size();
	}
	
	private static int getNumberOfDigits(int min, int max) {
		String s1 = String.valueOf(min);
		String s2 = String.valueOf(max);
		if (s1.length() == s2.length()) return s1.length();
		throw new RuntimeException("Minimum and Maximum values have different numberOfDigits");
	}

	private static boolean isValid(int finalNumber, int sourceNumber, int min, int max) {
		return finalNumber > sourceNumber && finalNumber <=max; 
	}

	public static void main(String[] args) {
		System.out.println(getRecycledNumbersCount(10,99));
		System.out.println(getRecycledNumbersCount(162,939));
		System.out.println(getRecycledNumbersCount(112,989));
		System.out.println(getRecycledNumbersCount(100,100));
		System.out.println(getRecycledNumbersCount(182,983));
		System.out.println(getRecycledNumbersCount(129,963));
		System.out.println(getRecycledNumbersCount(167,943));
		System.out.println(getRecycledNumbersCount(158,947));
		System.out.println(getRecycledNumbersCount(105,992));
		System.out.println(getRecycledNumbersCount(123,941));
		System.out.println(getRecycledNumbersCount(104,994));
		System.out.println(getRecycledNumbersCount(364,749));
		System.out.println(getRecycledNumbersCount(152,946));
		System.out.println(getRecycledNumbersCount(135,927));
		System.out.println(getRecycledNumbersCount(100,999));
		System.out.println(getRecycledNumbersCount(142,993));
		System.out.println(getRecycledNumbersCount(177,921));
		System.out.println(getRecycledNumbersCount(103,966));
		System.out.println(getRecycledNumbersCount(122,996));
		System.out.println(getRecycledNumbersCount(120,976));
		System.out.println(getRecycledNumbersCount(271,271));
		System.out.println(getRecycledNumbersCount(101,921));
		System.out.println(getRecycledNumbersCount(115,976));
		System.out.println(getRecycledNumbersCount(137,959));
		System.out.println(getRecycledNumbersCount(139,915));
		System.out.println(getRecycledNumbersCount(1,2));
		System.out.println(getRecycledNumbersCount(49,83));
		System.out.println(getRecycledNumbersCount(114,962));
		System.out.println(getRecycledNumbersCount(37,53));
		System.out.println(getRecycledNumbersCount(114,982));
		System.out.println(getRecycledNumbersCount(158,931));
		System.out.println(getRecycledNumbersCount(314,801));
		System.out.println(getRecycledNumbersCount(140,989));
		System.out.println(getRecycledNumbersCount(172,958));
		System.out.println(getRecycledNumbersCount(393,646));
		System.out.println(getRecycledNumbersCount(112,986));
		System.out.println(getRecycledNumbersCount(136,912));
		System.out.println(getRecycledNumbersCount(112,938));
		System.out.println(getRecycledNumbersCount(109,964));
		System.out.println(getRecycledNumbersCount(166,969));
		System.out.println(getRecycledNumbersCount(150,965));
		System.out.println(getRecycledNumbersCount(150,944));
		System.out.println(getRecycledNumbersCount(104,925));
		System.out.println(getRecycledNumbersCount(102,919));
		System.out.println(getRecycledNumbersCount(175,937));
		System.out.println(getRecycledNumbersCount(189,991));
		System.out.println(getRecycledNumbersCount(133,996));
		System.out.println(getRecycledNumbersCount(190,984));
		System.out.println(getRecycledNumbersCount(2,7));
		System.out.println(getRecycledNumbersCount(744,744));
	}
}
