/*
 * 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.util.Scanner;

/**
 *
 * @author krishna
 */
public class Recycled {
   

    public static void main(String[] args) {
        Program();
    }

    public static void Program() {
        Scanner inp = new Scanner(System.in);
        String line;
        String nor[];
        int num1, num2;
        int test = Integer.parseInt(inp.nextLine());
        int num = 1;
        while (num <= test) {
            line = inp.nextLine();
            nor = line.split(" ");
            num1 = Integer.parseInt(nor[0]);
            num2 = Integer.parseInt(nor[1]);
            System.out.println("Case #"+num+": "+CountNum(num1, num2));
            num++;
        }


    }

    public static int CountNum(int num1, int num2) {
        int count = 0;
        int goMax[]={9,99,999,9999,99999,999999};
        int goMin[]={0,10,100,1000,10000,100000};
        int length;
        for (int x = num1; (x < num2) && !leadingZeros(x); x++) {
            {
                 length=Integer.valueOf(x).toString().length();
                 count +=found(x,Math.max(num1,(int)goMin[length-1]),(int)Math.min(num2,goMax[length-1]));
                     
            }
        }

        return count;
    }

    private static int found(int num, int min, int max) {
     
        int part1;
        int part2;
        int zero=10;
        String join;
        int rem;
        int count=0;
          while(num/zero !=0)
          {
              rem=num%zero;
           
              part1=rem;
              part2=num/zero;
              
                
              join=part1+""+part2;
              zero =zero*10;
             if(Integer.parseInt(join)>=min && Integer.parseInt(join)<=max && Integer.parseInt(join) > num  && checkLength(num,join)  ){
                  
                  count++;
              }
             
              if(alternate(join,max))
                  count--;
          }
        return count;
    }
 public static boolean leadingZeros(int num)
{
  String str=num+"";
  if(str.charAt(0)=='0')
      return true;
  else
      return false;
      
}
 public static boolean checkLength(int num1,String str2)
 {
     String str1=num1+"";
     if(str1.length() == str2.length())
         return true;
     else
         return false;
 }
 public static boolean alternate(String str,int max)
 {
     String str2=str.substring(1);
     str2=str2+str.charAt(0);
     if(str==str2)
     {
         return true;
     }
     else
         return false;
 }
}

