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.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;


public class RecycledNumbers {
	
	public static long shift(long a, byte n){
		return ((a % (long)Math.pow(10, n-1)) * 10 + (a / (long)Math.pow(10, n-1)));
	}
	
	public static byte numberOfDigits(long a){
		byte n = 0;
		while (a > 0){
			n++;
			a /= 10;
		}
		return n;
	}
	
	public static void main(String[] args){
		File in = new File(args[0]);
		File out = new File("c.out");
		FileOutputStream w = null;
		Scanner s = null;
		try{
			w = new FileOutputStream(out);
			s = new Scanner(in);
		} catch (FileNotFoundException e) {}
		int n = s.nextInt();
		for (int i = 1; i <= n; i++){
			long a = s.nextLong();
			long b = s.nextLong();
			byte an = numberOfDigits(a);
			long count = 0;
			
			for(long j = a; j<=b; j++){
				List<Long> l = new LinkedList<Long>();
				long num = j;
				for (byte k = 1; k < an; k++){
					num = shift(num, an);
					if ((num > j) && (num <= b) && !l.contains(num)){
						l.add(num);
						count++;
					}
				}
			}
			try {
				w.write(("Case #"+ i +": "+count+"\r\n").getBytes());
			} catch (IOException e) {
			}
		}
		try {
			w.close();
			s.close();
		} catch (IOException e) {}
	}

}
