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.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution3 {
	
	public static void main(String[] args) throws Exception {
		System.out.println(
			parseOfFile(new File("C:\\code\\teste.txt"))
		);
	}
	
	public static String parseOfFile(File file) throws Exception {
		FileInputStream fstream = new FileInputStream(file);
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));

		StringBuffer sb = new StringBuffer();

		String strLine;
		while ((strLine = br.readLine()) != null) {
			sb.append(strLine.trim());
			sb.append("\n");
		}

		return parser(sb.toString());
	}
	
	public static String parser(String string) {
		String[] lines = string.split("\n");
		StringBuffer sb = new StringBuffer();
		
		for (int index = 1; index < lines.length; index++) {
			String[] values = lines[index].split(" ");
			int a = Integer.parseInt(values[0]);
			int b = Integer.parseInt(values[1]);
			
			sb.append("Case #");
			sb.append(index);
			sb.append(": ");
			sb.append(quantidade(a, b));
			
			if (index != lines.length - 1) sb.append("\n");
		}
		
		return sb.toString();
	}
	
	public static int quantidade(int a, int b) {
		List<Integer> availablesNumbers = new ArrayList<Integer>();
		Set<Pair> pairs = new HashSet<Pair>();
		
		for (int number = a; number <= b; number++) 
			availablesNumbers.add(number);
		
		for (Integer integer : availablesNumbers) {
			String string = integer.toString();
			for (int index = 1; index <= string.length(); index++) {
				String newString = string.substring(index) + string.substring(0, index);
				Integer newNumber = Integer.parseInt(newString);
				
				if (!availablesNumbers.contains(newNumber)) continue;
				if (integer.equals(newNumber)) continue;
				if (integer < newNumber) continue;
				
				pairs.add(new Pair(integer, newNumber));
			}
		}
		
		return pairs.size();
	}
	
	public static class Pair {
		Integer a;
		Integer b;
		
		public Pair(int a, int b) {
			this.a = a;
			this.b = b;
		}
		
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + ((a == null) ? 0 : a.hashCode());
			result = prime * result + ((b == null) ? 0 : b.hashCode());
			return result;
		}
		
		@Override
		public boolean equals(Object obj) {
			if (obj.getClass() != Pair.class) return false;
			Pair other = (Pair) obj;
			
			if (other.a.equals(a) && other.b.equals(b)) return true;
			if (other.a.equals(b) && other.b.equals(a)) return true;
			if (other.b.equals(a) && other.a.equals(b)) return true;
			
			return false;
		}
		
		@Override
		public String toString() {
			return "[ " + a + ", " + b + " ]";
		}
	}

}
