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

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

package google.jam;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;

public class RecycledNumbers {
	
	public static void main (String[] args){
		System.out.println("Please, type your input:");
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		boolean checkLines = false;
		int numLines = 0, linesCounter = 0;
		String line;
		String output = "";
		try {
			while((line = stdIn.readLine()) != null){
				if(!checkLines){
					numLines = Integer.parseInt(line);
					checkLines = true;
				}else{
					linesCounter++;
					output += inputToOutput(line, String.valueOf(linesCounter));
				}
				if(linesCounter >= numLines)
					break;
			}	
			System.out.println(output);
		} catch (IOException e) {
			System.out.println("Something went wrong with your input.");
			e.printStackTrace();
		}
	}
	
	public static String inputToOutput(String input, String lineNum){
		TreeSet<String> set = new TreeSet<String>();
		String[] numbers = input.split(" ");
		
		if(numbers.length != 2)
			return "Case #" + lineNum + ": 0\n";
		
		int start = Integer.parseInt(numbers[0]);
		int end = Integer.parseInt(numbers[1]);
		if(start >= end)
			return "Case #" + lineNum + ": 0\n";
		
		int cur = start;
		while(cur <= end){
			for(int i=String.valueOf(cur).length()-1; i>0; i--){
				String number = String.valueOf(cur);
				if(number.charAt(i) == '0')
					continue;
				String newNum = number.substring(i) + number.substring(0, i);
				int newInt = Integer.parseInt(newNum);
				if( newInt > end || newInt < start || newNum.equals(number) )
					continue;
				set.add( (number.compareTo(newNum) < 0)?(newNum+number):(number+newNum) );
			}
			cur++;
		}
		
		return "Case #" + lineNum + ": " + set.size() + "\n";
	}

}
