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

import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;

/**
 *
 * @author imgps
 */
public class C {
    public static void main(String args[]) throws Exception{
        int A,B;
        int ctr = 0;
        int testCases;
        
        Scanner sc = new Scanner(new FileInputStream("C-small-attempt0.in "));
        testCases = sc.nextInt();
        int input[][] = new int[testCases][2];
        for(int i=0;i<testCases;i++)
        {
          //  System.out.print("Enter input A B: ");
            input[i][0] = sc.nextInt();
            input[i][1] = sc.nextInt();
            
        }
  

for(int k=0;k<testCases;k++){
      ctr = 0;
      A = input[k][0];
      B = input[k][1];
        for(int i = A;i<=B;i++){
            int num = i;
            int nMul = 1;
            int mul = 1; 
            int tnum = num/10;
            while(tnum > 0){
                mul = mul *10;
                tnum= tnum/10;
            }
            tnum = num;
            int n = 0;
            while(tnum > 0 && mul >= 10){
                nMul = nMul * 10;
                n = (num % nMul) * mul + (num / nMul);
                mul = mul / 10;
                tnum = tnum / 10;
                for(int m=num;m<=B;m++){
                    
                    if(n == m && m > num){
                        ctr++;
                    }
                }
                
                
                
         
            }
        }
        System.out.println("Case #"+(k+1)+": "+ctr);
        
    }
    }
}

import java.lang.*;
import java.io.*;
import java.util.*;

public class rotate{

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

int i,j,k,m;
int n_test_case;
FileInputStream fin = new FileInputStream("C-small-attempt0.in");
DataInputStream in = new DataInputStream(fin);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String str,tempN,tempM;
String ABstr[]=new String[2];
            FileWriter fout = new FileWriter("output.txt");
            BufferedWriter out = new BufferedWriter(fout);

            str = br.readLine();
            n_test_case=Integer.parseInt(str);

            for(i=0;i<n_test_case;i++)
            {
                int count=0;
                str = br.readLine();    
                ABstr = str.split(" ");
                //System.out.println(ABstr[0]+" "+ABstr[1]);
                int A,B;
                A=Integer.parseInt(ABstr[0]);//n
                B=Integer.parseInt(ABstr[1]);//m
                    for(j=A;j<B;j++)
                    {
                        ArrayList<Object> arl=new ArrayList<Object>();
                        for(k=j+1;k<=B;k++)
                        {
                            tempN= new Integer(j).toString();//n
                            tempM= new Integer(k).toString();//m
                            if(ABstr[0].length()>1)
                            {

                                 for(m=0;m<ABstr[0].length();m++)
                                 {
                                 
                                 //rotate
                                 if(tempN.equals(tempM) && arl.indexOf(tempN)==-1)
                                 {
                                     //System.out.println(tempN+" "+tempM);
                                     arl.add(tempN);
                                     count++;
                                     
                                 }
                                 else
                                 tempN=tempN.substring(tempN.length()-1,tempN.length())+tempN.substring(0,tempN.length()-1);
                                 while(tempN.charAt(0)=='0')    
                                 tempN=tempN.substring(tempN.length()-1,tempN.length())+tempN.substring(0,tempN.length()-1);
                                 }
                                
                            }
                            
                        }
                                                
                    }//each value of n is compared
                //System.out.println(count);
            if(i==n_test_case-1)
            str="Case #"+(i+1)+": "+count;
            else
            str="Case #"+(i+1)+": "+count+"\n";
            out.write(str);

            }//outer n_test_cases loop
            out.close();
}
}