import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		int casos=1, a, b, n, m, cont;
		while(t!=0){
			a=sc.nextInt();
			b=sc.nextInt();
			if(a>b){
				int aux=a;
				a=b;
				b=aux;
			}
			System.out.printf("Case #%d: ",casos++);
			if(a==b){
				System.out.printf("%d\n",0);
			}else{
				cont=0;
				for(n=a;n<b;n++){					
					for(m=n+1;m<=b;m++){					
						if(isRecycled(n,m)) cont++;
					}
				}
				System.out.printf("%d\n",cont);
			}
			t--;
		}		
	}
	public static boolean isRecycled(int n1, int n2){
		String s1, s2, aux;
		s1 =  String.valueOf( n1 );
		s2 =  String.valueOf( n2 );		
		boolean r = false;		
		for(int i=0;i<s1.length();i++){
			aux="";
			aux=s1.substring(i,s1.length())+s1.substring(0,i);
//			System.out.println(aux);
			if(aux.equals(s2)){
				r=true;
				break;
			}
		}		
		return r;
	}
}

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

package google_jamp_c;
import java.io.*;
import java.util.*;
/**
 *
 * @author sabri
 */

public class Google_jamp_c {

    /**
     * @param args the command line arguments
     */
public static int recycled (int A, int B){
                int m = 0, c=0;
                String tmp = "", subB = "", subE = "", recycled = "";
                for (int n = A; n<B;n++)
                {
                        tmp = String.valueOf(n);
                        for (int j=0;j<tmp.length();j++)
                        {
                            subB = tmp.substring(0,j);
                            subE = tmp.substring(j);
                            recycled = subE+subB;
                            m = Integer.parseInt(recycled);
                            if ((m>n) && (m<=B)) 
                             {c++;}
                        }
                }
                return c;
        }
    public static void main(String[] args) throws FileNotFoundException, IOException {
        String ligne = "";
        int nbrLigne = 0,res,a,b;
        StringTokenizer st1;
        FileInputStream fStream = new FileInputStream("A-small-attempt.in");
		BufferedReader in = new BufferedReader(new InputStreamReader(fStream));
                if (in.ready()) {
			ligne = in.readLine();
			nbrLigne = Integer.parseInt(ligne);
      			for (int j = 0; j < nbrLigne; j++) {
				ligne = in.readLine();
                                st1=new StringTokenizer(ligne," ");
                                 a=Integer.parseInt(st1.nextToken());
                                  b=Integer.parseInt(st1.nextToken());
				System.out.print("Case #"+(j+1)+": ");
                                res=recycled(a,b);
                                System.out.print(res);
                          System.out.println("");
			}
		}
    }
}
