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.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;

public class ProblemC {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		BufferedReader br = null;
		BufferedWriter bw = null;
		String input = null;
		StringBuffer output = null;
		String[] twonumbers = null;
		int min = 0, max = 0;
		ArrayList<String> list = null;
		String temp = null;
		String strmin = "";
		int tempint = 0;
		int counter = 0;
		int digit1 = 0, digit2 = 0;
		try {
			br = new BufferedReader(new FileReader(new File(
					"C:/Users/DHAVAL/Downloads/Input1.txt")));
			bw = new BufferedWriter(new FileWriter("output1.txt"));
			int count = Integer.parseInt(br.readLine());
			for (int i = 0; i < count; i++) {
				input = br.readLine();
				output = new StringBuffer("Case #" + (i + 1) + ": ");
				counter=0;
				// logic here
				list = new ArrayList<String>();
				twonumbers = input.split(" ");
				min = Integer.parseInt(twonumbers[0]);
				max = Integer.parseInt(twonumbers[1]);
				if (max >= 10) {
					for (int j = min; j <= max; j++) {
						strmin = "" + j;
						temp = strmin;
						for (int k = 0; k < strmin.length() - 1; k++) {
							temp = temp.substring(1) + temp.charAt(0);
							tempint = Integer.parseInt(temp);
							digit1 = ("" + tempint).length();
							digit2 = strmin.length();
							if (j < tempint && digit1 == digit2
									&& tempint >= min && tempint <= max
									&& !list.contains(strmin + "||" + temp)
									&& !temp.equals(strmin)) {
								//System.out.println(strmin + " " + tempint);
								// list.add(temp);
								list.add(strmin + "||" + temp);
								counter++;
							}
						}
					}
				}
				bw.write(output.toString() + counter);
				bw.newLine();
			}
			bw.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
