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.util.*;
import java.io.*;

public class C{
	
	public static void main(String[] args) throws IOException{
		Scanner inp = new Scanner(new File("C-large.in"));
		PrintWriter pw = new PrintWriter(new FileWriter("c-large.out"));
		
		int numCases = inp.nextInt();
		
		for (int cas = 0; cas < numCases; cas++){
			pw.print("Case #" + (cas+1) + ": ");
			
			/* case input */
			int A = inp.nextInt();
			int B = inp.nextInt();
			/* end case input */
			
			int ABak = A;
			int numDigits = 0;
			while (ABak > 0){
				ABak /= 10;
				numDigits++;
			}
			
			int ans = 0;
			
			/* main logic */
			for (int i = A; i < B; i++){
				
				Set<Integer> validMs = new HashSet<Integer>();
				for (int j = 1; j < numDigits; j++){
					int b = shift(i, j, numDigits);
					
					if (b <= B && b > i){
						validMs.add(new Integer(b));
					}
				}
				ans += validMs.size(); 
			}
			pw.println(ans);
		}
		pw.close();
	}
	
	public static int shift(int x, int k, int l){
		//int d = (int) Math.pow(10, k);
		int d = 1;
		for (int p = 1; p <= k; p++){
			d *= 10;
		}
		int tmp = x % d;
		int d2 = 1;
		for (int p = 1; p <= (l - k); p++){
			d2 *= 10;
		}
		tmp *= d2;
		return ((x/d) + tmp);
	}
}
