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

/**
 *
 * @author Sriram
 */
//import static java.lang.System.*;
import java.util.*;
import java.io.*;

public class RecycledNumbers_GCJ_2012{

    public static void main(String args[]) throws Exception
    {
      Scanner in = new Scanner(new java.io.FileInputStream("f:\\input.in"));
      PrintStream out = new PrintStream(new FileOutputStream("f:\\output.out"));
      int T = in.nextInt();
      for(int zz=0; zz<T;zz++)
      {
          int A,B;
          A = in.nextInt();
          B = in.nextInt();
          HashSet<Integer> s = new HashSet<Integer>();
          int count = 0;
          for(int i=A;i<(B+1);i++)
          {
              int[] perm = rotations(i);
              for(int e: perm)
              {
                  if((e>=A)&&(e<=B)&&(e>i))
                  {
                     s.add(e);
                     count++;
                  }
              }
          }
          out.printf("Case #%d: %d\n",(zz+1),count);
      }
    }

    static int[] rotations(int n) {
        // Max places for small set: 4
        // Max places for large set: 7
        if((n/1000000)>0)
        {
            int a,b,c,d,e,f,g;
            g = n%10;
            n/=10;
            f = n%10;
            n/=10;
            e = n%10;
            n/=10;
            d = n%10;
            n/=10;
            c = n%10;
            n/=10;
            b = n%10;
            n/=10;
            a = n%10;
            return new int[]{(a*1000000+b*100000+c*10000+d*1000+e*100+f*10+g),(b*1000000+c*100000+d*10000+e*1000+f*100+g*10+a),(c*1000000+d*100000+e*10000+f*1000+g*100+a*10+b),(d*1000000+e*100000+f*10000+g*1000+a*100+b*10+c),(e*1000000+f*100000+g*10000+a*1000+b*100+c*10+d),(f*1000000+g*100000+a*10000+b*1000+c*100+d*10+e),(g*1000000+a*100000+b*10000+c*1000+d*100+e*10+f)};
        }
        if((n/100000)>0)
        {
            int a,b,c,d,e,f;
            f = n%10;
            n/=10;
            e = n%10;
            n/=10;
            d = n%10;
            n/=10;
            c = n%10;
            n/=10;
            b = n%10;
            n/=10;
            a = n%10;
            return new int[]{(a*100000+b*10000+c*1000+d*100+e*10+f),(b*100000+c*10000+d*1000+e*100+f*10+a),(c*100000+d*10000+e*1000+f*100+a*10+b),(d*100000+e*10000+f*1000+a*100+b*10+c),(e*100000+f*10000+a*1000+b*100+c*10+d),(f*100000+a*10000+b*1000+c*100+d*10+e)};
        }
        if(n/10000>0)
        {
          int a,b,c,d,e;
          e = n%10;
          n/=10;
          d = n%10;
          n/=10;
          c = n%10;
          n/=10;
          b = n%10;
          n/=10;
          a = n%10;
          return new int[]{(a*10000+b*1000+c*100+d*10+e),(b*10000+c*1000+d*100+e*10+a),(c*10000+d*1000+e*100+a*10+b),(d*10000+e*1000+a*100+b*10+c),(e*10000+a*1000+b*100+c*10+d)};
        }
        if((n/1000>0))
        {
        if (n == 1000) {
            return new int[]{1000, 100, 10, 1};
        }
        int a,b,c,d;
        d = n%10;
        a = n/1000;
        b = (n-(a*1000))/100;
        c = ((n%100)-d)/10;
        return new int[]{(a*1000+b*100+c*10+d),(b*1000+c*100+d*10+a),(c*1000+d*100+a*10+b),(d*1000+a*100+b*10+c)};
        }
        if ((n / 100) > 0) {
            if (n == 100) {
                return new int[]{100, 10, 1};
            }
            int x, y, z;
            z = n%10;
            x = n/100;
            y = (n-(x*100)-z)/10;
            return new int[]{(x * 100) +(y * 10) + z, (y * 100 + z * 10 + x), (z * 100 + x * 10 + y)};
        }
        if((n/10)>0)
        {
            if(n == 10)
                return new int[]{10,1};
            int x,y;
            x = n/10;
            y = n%10;
            return new int[]{x*10+y,y*10+x};
        }
        return new int[]{n};

    }
}
