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.*;
import java.util.Set;
import java.util.HashSet;

public class Recycler {
	public static void main(String[] args)
		throws IOException, FileNotFoundException {

		StreamTokenizer st = new StreamTokenizer(
				new FileReader(args[0]));

		FileWriter out = new FileWriter(args[1]);

		st.parseNumbers();
		if (st.nextToken() == StreamTokenizer.TT_EOF) eof_error();

		int numTestCases = (int) st.nval;
		int numDistinctPairs = 0;
		boolean twins = false;
		Set<Integer> partners = new HashSet<Integer>();

		for (int t = 0; t < numTestCases; ++t) {

			if (st.nextToken() == StreamTokenizer.TT_EOF) eof_error();
			int A = (int) st.nval;
			if (st.nextToken() == StreamTokenizer.TT_EOF) eof_error();
			int B = (int) st.nval;

			for (int i = A; i < B; ++i) {

				String curNumberString = String.valueOf(i);

				for(int j = 1; j < curNumberString.length(); ++j) {

					String sub1 = curNumberString.substring(j);
					String sub2 = curNumberString.substring(0, j);

					String test = sub1 + sub2;


					if (Integer.valueOf(test) > i &&
							Integer.valueOf(test) <= B) {

						if (! partners.contains(Integer.valueOf(test))) {
							++numDistinctPairs;
							partners.add(Integer.valueOf(test));
						}

					}

				}

				partners.clear();
			}
			out.write("Case #" + (t+1) + ": " + numDistinctPairs + "\n");
			numDistinctPairs = 0;
		}

		out.close();
	}

	private static void eof_error() {
		throw new RuntimeException("Unexpected end of file reached");
	}
}
