import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

	}
	
	
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Recycled {

	
	public static boolean isRecycled(int a, int b) {
		String left = a+"";
		String right = b+"";
		if(left.length()!=right.length()) return false;
		int l = left.length();
		for(int i=0;i<l;i++) {
			boolean o = true;
			for(int j=0;j<l;j++) {
				if(left.charAt((i+j)%l) == right.charAt(j)) continue;
				else o=false;
			}
			if(o) return true;
		}
		return false;
	}
	
	public static int next(int in) {
		int p = (int) (Math.log(in)/Math.log(10));
		int last = in - Math.abs(in/10)*10;
		if(last==0) return 0;
		return (int) (last*Math.pow(10, p) + in/10);
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
//		System.out.println(isRecycled(12345, 234521));
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		int cases = Integer.parseInt(in.readLine());
		for (int i = 1; i <= cases; i++) {
			String[]e = in.readLine().trim().split(" ");
			int A = Integer.parseInt(e[0]);
			int B = Integer.parseInt(e[1]);
			
			int count = 0;
			
			for(int x=A;x<B;x++) for(int y=x+1;y<=B;y++) if(isRecycled(x, y)) count ++;
			
			System.out.println("Case #"+i+": "+count);
		}
	}
	
}
