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

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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Hashtable;

/**
 *
 * @author PARIMAL
 */
public class RecycledNumbers {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        String inputFile = "E:\\C-large.in";
        String outputFile = "E:\\C-large.out";

        File f = new File(inputFile);
        FileInputStream fis = null;
        BufferedReader reader = null;

        try {
            fis = new FileInputStream(f);
            reader = new BufferedReader(new InputStreamReader(fis));
            String line = reader.readLine();
            //ret=line.split(" ");

            int loopCount = Integer.parseInt(line);

            int i;
            int a, b;
            long A, B;
            int RecycledPairs[] = new int[loopCount];
            for (int j = 0; j < RecycledPairs.length; j++) {
                RecycledPairs[j] = 0;
            }
            //System.out.println("loop"+loopCount);
            String out[] = new String[loopCount];
            String bounds[] = new String[2];

            for (i = 0; i < loopCount; i++) {

                String t = reader.readLine();
                bounds = t.split(" ");
                A = Long.parseLong(bounds[0]);
                B = Long.parseLong(bounds[1]);

                int lengthA = bounds[0].length();

                if (lengthA == 1) {
                    RecycledPairs[i] = 0;
                    out[i] = String.valueOf(RecycledPairs[i]);
                } else {
                    String tempA, lastA, firstA, finalA;
                    long finalAns;

                    //for (int j = a; j <= b; j++) {
                        //init
                        long jL=A;
                        while(jL<=B){
                        tempA = String.valueOf(jL);
                        //System.out.println("tempA " + tempA);


                        for (int k = 1; k < lengthA; k++) {
                            lastA = tempA.substring(lengthA - k);    //12345 ==> 45

                            //System.out.println("lastA "+lastA);
                            //System.out.println("firstA "+firstA);

                            if (Long.parseLong(lastA) == 0) {
                                //System.out.println("Encountered zeros with " + k + " times");
                            } else {

                                firstA = tempA.substring(0, lengthA - k);

                                finalA = lastA + firstA;

                                finalAns = Long.parseLong(finalA);
                                if (jL < finalAns && finalAns <=B) {
                                    RecycledPairs[i]++;
                                    //System.out.println("Re: " + RecycledPairs[i]);
                                }
                            }

                        }
                        out[i] = String.valueOf(RecycledPairs[i]);
                        jL++;
                    }
                }

            }



            for (int j = 0; j < loopCount; j++) {
                String o = " ";
                StringBuffer sB = new StringBuffer(100);
                sB.append("Case #" + (j + 1) + ": ");

                o=sB.append(out[j]).toString();

                out[j] = o;
            }



            FileOutputStream fileOutputStream = null;
            try {
                File fOut = new File(outputFile);
                fileOutputStream = new FileOutputStream(fOut);

                for (int m = 0; m < out.length; m++) {

                    out[m] += "\n";
                    byte[] bytes = out[m].getBytes();
                    fileOutputStream.write(bytes);
                }


                fileOutputStream.flush();
                fileOutputStream.close();

                fis.close();

        } catch (IOException ex) {
            ex.printStackTrace();
        }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
