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

public class RecycledNumbers{

    public static void main(String[] args){
	Scanner scanner = new Scanner(System.in);
	int num = Integer.parseInt(scanner.nextLine());
	for(int i = 1; i <= num; ++i){
	    String[] tokens = scanner.nextLine().split(" ");
	    int lower = Integer.parseInt(tokens[0]);
	    int upper = Integer.parseInt(tokens[1]);
	    RecycledNumbers r =  new RecycledNumbers();
	    System.out.println("Case #" + i + ": " + r.recycledNumbers(lower, upper));
	}
    }

    public int recycledNumbers(int a , int b){
	this.lower = a;
	this.upper = b;
	for(int i = a; i <= b; ++i){
	    findAllRecycleNumbers(i);
	}
	return numRecycleNumbers;
    }

    public void findAllRecycleNumbers(int i){
	Set<Integer> pairs = new HashSet<Integer>();
	int power  = getPower(i);
	int recycleNumber = i;
	for(int count = 0; count <= power; ++count){
	    int quotient = recycleNumber / 10;
	    int remainder = recycleNumber % 10;
	    recycleNumber = (int)Math.pow(10, power) * remainder + quotient;
	    if(recycleNumber >= lower && recycleNumber > i && recycleNumber <= upper){
		if(!pairs.contains(recycleNumber)){
		    pairs.add(recycleNumber);
		    ++numRecycleNumbers;
		}
	    }
	}	
    }
    
    private int getPower(int i){
	int pow = 0;
	while(i > 9){
	    i /= 10;
	    ++pow;
	}
	return pow;
    }	

    public static class Pairs{
	int lower;
	int upper;
	public Pairs(int lower, int upper){
	    this.lower = lower;
	    this.upper = upper;
	}

    }
    private int numRecycleNumbers;
    private int lower;
    private int upper;
}