import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

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

package actual;

import codejam.*;
import java.io.*;
import java.util.Scanner;
/**
 *
 * @author atm
 */
public class PCL {
   public static void main(String[] args) throws Exception {
       int Cases;
       int L,U;
       String words[];
       
        FileInputStream fstreamIN = new FileInputStream("F:\\codejam\\input\\C-large.in");
        FileOutputStream fstreamOUT = new FileOutputStream("F:\\codejam\\output\\C-large.out");
        
        Scanner in=new Scanner(fstreamIN);
        PrintWriter out=new PrintWriter(fstreamOUT);
        
        Cases=in.nextInt();
        
        for(int i=0;i<Cases;i++) // Cases loop
        {
            L=in.nextInt();
            U=in.nextInt();
            int ans=0;
            if(L==1000){
                ans=0;
            }else if(L<10){
                ans=0;
            }else if(L<100){
                
                for(int j=L;j<=U;j++){ 
                    if(revtwo(j)<=U){
                        if(revtwo(j)>j)
                            ans++;                        
                    }
                }
            } else {
                for(int j=L;j<=U;j++){ 
                    String num=Integer.toString(j);
                    for(int k=0;k<num.length();k++){
                        if(ndigcir(j,k)<=U){
                            if(ndigcir(j,k)>j)
                                ans++;                        
                        }
                    }                  
                    
                }               
            } 
             out.printf("Case #%d: %d\n",i+1,ans);
        }
        out.close();   
   }
   static int revtwo(int num){
       return (num%10)*10+(num/10);
   }
   static int onedigcir(int num)
   {
       int newnum;
       newnum=(num%10)*100+(num/10);
       return newnum;
   }
   static int twodigcir(int num)
   {
       int newnum;
       newnum=(num%100)*10+(num/100);
       
       return newnum;
   }
   static int ndigcir(int num,int n)
   {
       String number=Integer.toString(num);
       String right=number.substring(number.length()-n, number.length());
       String newNum=right+number.substring(0,number.length()-n);
       return Integer.parseInt(newNum);
   }
}
