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;
	}
}

import java.io.*;
public class ProblemC {
    public static void main(String args[]) {
        try {
            BufferedReader br = new BufferedReader(new FileReader("E:\\test.txt"));
            int no;
            no= Integer.parseInt(br.readLine());
            int casen=0,i,j;
            int a,b,count;
            String temp,t,u;
            String output;
            output="";
            String spl[];
            String memory,fp,lp;
            while( casen < no ) {
                temp = br.readLine();
                output += "Case #"+(casen+1)+": ";
                spl = temp.split(" ");
                a = Integer.parseInt(spl[0]);
                b = Integer.parseInt(spl[1]);
                count = 0;
                memory = "";
                for(i=a;i<=b; i++) {
                	t = i+"";
                	for(j=1;j<t.length();j++) {
                		u= t.substring(j);
                		u+= t.substring(0,j);
                		//System.out.println(u);
                		if( !u.startsWith("0") && Integer.parseInt(u) < i && Integer.parseInt(u)<= b && Integer.parseInt(u) >= a)
                		{
                			if( t.length() % 2 == 0 ) {
                				fp= t.substring(0,t.length()/2);
                				lp = t.substring(t.length()/2);
                				if( fp.equals(lp) ) {
                					if(!memory.contains(Integer.parseInt(u)+" "+i)) {
                						count++;
                						memory += Integer.parseInt(u) + " " + i+"\n";
                					}
                				}
                				else {
                					count++;
                				}
                			}
                			else {
                				count++;
                			}
                			/*if( memory.contains(Integer.parseInt(u)+" "+i) )
                				System.out.println(Integer.parseInt(u)+"  "+i);
                			else
                			{
                				count++;
                				memory += Integer.parseInt(u) + " " + i+"\n";
                			}*/
                		}
                	}
                }
                output += count;
                if( casen != no-1 )
                    output += "\n";
                casen++;
            }
            BufferedWriter bw = new BufferedWriter( new FileWriter("E:\\result.txt"));
            bw.write(output);
            bw.close();
            br.close();
        }
        catch( Exception e )
        {
            e.printStackTrace();
        }
    }
}