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

package year_2012.qualification;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author paul
 * @date 14 Apr 2012
 */
public class QuestionC {

    private static Set<Integer> getCycle(int x) {

        String s = Integer.toString(x);
        Set<Integer> set = new HashSet<Integer>();
        set.add(x);
        for (int c = 1; c < s.length(); c++) {
            String t = s.substring(c).concat(s.substring(0, c));
            set.add(Integer.parseInt(t));
        }
        return set;
        
    }

    private static Set<Integer> mask(Set<Integer> set, int a, int b) {
        Set<Integer> result = new HashSet<Integer>();

        for (int x : set) {
            if (x >= a && x <= b) {
                result.add(x);
            }
        }
        
        return result;

    }


    public static void main(String[] args) throws FileNotFoundException, IOException {

        String question = "C";

//        String name = "large";
        String name = "small-attempt0";
//        String name = "test";

        String filename = String.format("%s-%s", question, name);

        BufferedReader input = new BufferedReader(
                new FileReader(String.format("/home/paul/Documents/code-jam/2012/qualification/%s.in",
                filename)));

        String firstLine = input.readLine();

        PrintWriter pw = new PrintWriter(new File(
                String.format("/home/paul/Documents/code-jam/2012/qualification/%s.out", filename)));


        int T = Integer.parseInt(firstLine);

        // Loop through test cases.
        for (int i = 0; i < T; i++) {

//             Read data.
            String[] tokens = input.readLine().split(" ");

//            int N = Integer.parseInt(input.readLine());

            int A = Integer.parseInt(tokens[0]);
            int B = Integer.parseInt(tokens[1]);

//            System.out.format("%d, %d\n", A, B);

            boolean[] used = new boolean[B+1];
            int total = 0;
            for (int n = A; n <= B; n++) {
                if (!used[n]) {
                    Set<Integer> set = mask(getCycle(n), A, B);
                    int k = set.size();
                    total += (k * (k-1))/2;
                    for (int m : set) {
                        used[m] = true;
                    }
                }
            }

            pw.format("Case #%d: %d\n", i + 1, total);
        }

        pw.close();

    }

}

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

/**
 *
 * @author Dimitris
 */
import java.io.*;

public class trito {
    
  File ffff;
  FileReader fr;
  BufferedReader br;
 
  File fout;       
  FileWriter fw;
  BufferedWriter bw; 
  
    public static void main(String [] args){
        trito t=new trito();
      //  System.out.println(t.convert(109,121)); 
        t.run();
       
    }
    
 public void run(){
     try{
        ffff=new File("C:\\Users\\Dimitris\\Documents\\NetBeansProjects\\jam\\src\\C-small-attempt0.in");
        fr=new FileReader(ffff);
        br=new BufferedReader(fr);
    
        fout=new File("C:\\Users\\Dimitris\\Documents\\NetBeansProjects\\jam\\src\\output.out");
        fw=new FileWriter(fout);
        bw=new BufferedWriter(fw);
        
        
        int lo=new Integer(br.readLine());
        
        for(int i=1;i<=lo;i++){
            String s=br.readLine();
            String [] s2=s.split(" ");
           
            int [] tok=new int[s2.length];
            for(int iii=0;iii<s2.length;iii++) tok[iii]=new Integer(s2[iii]) ;
            
            String r=Integer.toString(convert(tok[0],tok[1]));
            bw.write("Case #"+i+": "+r);
            bw.write('\n');
            
        }
       br.close();
       bw.close();
     }
     catch(Exception e){
         e.printStackTrace();
     }
 }   

 
 public int convert(int aa,int bb){
  int A=aa;
  int B=bb;
  int res=0;
  
  for(int m=B;m>A;m--){  
    
    for(int n=A;n<m;n++){   
        
        
                 
        String s=Integer.toString(n);
         
        char[] c=new char[s.length()];
        for(int i=0;i<s.length()-1;i++){
          
           c[0]=s.charAt(s.length()-1);
           
           for(int i2=1;i2<s.length();i2++){
             c[i2]=s.charAt(i2-1);
             
           }
           s=new String(c);
           
           int neo=new Integer(s);
          if(c[0]==0) continue;
            
           if(neo==m){
                 
                 res++;
                 break;
           }
        }
     
     } 
    }
    
    return res;
   
  }
}
    