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.File;
import java.io.PrintWriter;

import java.util.HashSet;
import java.util.Scanner;

/**
 * User: Sasha
 * Date: 09.04.12
 * Time: 19:13
 */
public class Main {
    private Scanner sc;
    private PrintWriter wr;
    
    private void prepare() throws Exception {
        sc = new Scanner(new File("C:\\Projects\\C-small-attempt0.in"));
        File file = new File("C:\\Projects\\out.txt");
        wr = new PrintWriter(file);
//        wr = new PrintWriter(System.out);
    }
    
    private void solve() {
        int n = sc.nextInt();

        for (int i = 0; i < n; ++i) {
            HashSet<String> set = new HashSet<String>();

            wr.print(String.format("Case #%d: ", (i + 1)));

            int a, b;
            a = sc.nextInt();
            b = sc.nextInt();

            int res = 0;
            for (int j = a; j < b; ++j) {
                res += cnt(j, a, b, set);
            }
            wr.println(res);
        }

        wr.flush();
    }

    private int cnt(int c, int left, int right, HashSet<String> set) {
        int res = 0;
        String s = "" + c;
        for (int i = 0; i < s.length() - 1; ++i) {
            String t = s.substring(i + 1) + s.substring(0, i + 1);
            int d = Integer.parseInt(t);
            if (left <= d && d <= right && c < d && s.length() == ("" + d).length()) {
                if (set.contains(s + t)) continue;
                set.add(s + t);
                ++res;
            }
        }
        return res;
    }

    public static void main(String args[]) throws Exception {
        Main main = new Main();
        
        main.prepare();
        
        main.solve();
    }
}
