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

public class recycled {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(new File("input"));
		int size = sc.nextInt();

		for (int x = 0; x < size; x++) {
			TreeSet<String> set = new TreeSet<String>();
			TreeSet<String> set1 = new TreeSet<String>();
			int A = sc.nextInt();
			int B = sc.nextInt();
			int comb = 0;
			
			for (int w = A; w <= B; w++) {
				String str = w + "";

				if (str.length() >= 2 && good(str)) {
					//System.out.println(str);
					for (int y = 1; y < str.length(); y++) {
						int cons = Integer.parseInt(str.substring(y, str
								.length())
								+ str.substring(0, y));

						if (cons <= B && cons>=w) {
				
							comb++;
							set.add(str + " " + str.substring(y, str
									.length())
									+ str.substring(0, y));
						}
					}
				}
			}
			
			int comp = 0;
		
			for (int y = A; y <= B; y++)
				for (int z = y + 1; z <= B; z++) {
					boolean good = false;
					String yy = y + "";
					String zz = z + "";
					for (int k = 1; k < zz.length(); k++) {
						String cons = (zz
								.substring(k, zz.length())
								+ zz.substring(0, k));
						if ((cons + "").equals(yy)) {
							comp++;
							set1.add(yy + " " + zz);
							break;
						}
					}
				}
//			System.out.println(set);
//			set1.removeAll(set);
//			System.out.println(set1);
//			System.out.println(comb);
			System.out.println("Case #"+(x+1)+": "+comp);
		}

	}

	public static boolean good(String str) {
		int temp=str.charAt(0);
		for (int x = 1; x < str.length() - 1; x++)
			if (str.charAt(x)=='0')temp=0;
			else if(str.charAt(x)<temp)return false;
			else temp=str.charAt(x);
			
		if(str.length()==2 && str.charAt(0)==str.charAt(1))return false;
		return true;
	}
}
