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

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;


public class RecycledNumbers {
	
	static int[] p10 = {1,10,100,1000,10000,100000,1000000,10000000};
	
	public static int perm(int x, int n, int l){
		int y = x/p10[n];
		int z = x-y*p10[n];
		
		return z*p10[l-n] + y;
	}
	
	public static int longueur(int a){
		int i = 1;
		while(a / p10[i] != 0)
			i++;
		return i;
	}
	
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		File f = new File( "C-large.in" );
		FileWriter out=new FileWriter("output.txt");

		Scanner in = new Scanner(new FileReader(f));

		if(f.exists()){
			int T;
			int A, B;
			int r;
			int l;
			int y;
			Set<Integer> s = new LinkedHashSet<Integer>();
			
			T = in.nextInt();
			for(int i = 1; i <= T ; i++){
				A = in.nextInt();
				B = in.nextInt();
				l = longueur(A);
				r = 0;
				
				for(int x = A; x < B; x++){
					s.clear();
					for(int n = 1; n < l ; n++){
						y = perm(x, n, l);
						if(y > x && y <= B && !s.contains(y)){
							r++;
							s.add(y);
						}
					}
				}
				
				out.write("Case #" + i + ": " + r + "\n");
			}
	
		}

		in.close();
		out.close();

		
	}
	
	
}
