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.FileNotFoundException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

public class RecycledNumbers {
	public static void main(String args[]) throws FileNotFoundException {
		new RecycledNumbers().Go();
	}

	public void Go() throws FileNotFoundException {
		Scanner in = new Scanner(new File("test.txt"));
		int tests = Integer.parseInt(in.nextLine());
		for (int i = 0; i < tests; i++) {
			String[] line = in.nextLine().split("\\s+");
			int n = Integer.parseInt(line[0]);
			int m = Integer.parseInt(line[1]);
			System.out.println("Case #" + (i + 1) + ": "
					+ countPairs(n, m, 1, 1000));
		}
	}

	public int countPairs(int n, int m, int A, int B) {
		HashMap<Integer, LinkedList<Integer>> map = new HashMap<Integer, LinkedList<Integer>>();

		int count = 0;
		for (int i = n; i <= m; i++) {

			LinkedList<Integer> intList = permutations(i + "");
			map.put(i, intList);
			for (Integer it : intList) {
				if (map.containsKey(it)) {
					LinkedList<Integer> ints = map.get(it);
					if (ints.contains(i)) {
						count++;
					}
				}
			}
		}
		
		return count;
	}

	public LinkedList<Integer> permutations(String str) {
		LinkedList<Integer> numList = new LinkedList<Integer>();
		for (int i = 0; i < str.length(); i++) {
			Integer temp = Integer.parseInt(str);
			if (!numList.contains(temp))
				numList.add(Integer.parseInt(str));
			str = leftRotate(str);
		}
		numList.removeFirst();
		return numList;
	}

	public String leftRotate(String str) {
		StringBuilder build = new StringBuilder();
		build.append(str.substring(1, str.length()));
		build.append(str.charAt(0));
		return build.toString();
	}
}
