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

public class B {
	public static int reverse(int a, int b) {
		Vector vec = new Vector();
		Vector vec2 = new Vector();
		int result = 0;
		if(a > 9) {
			for(int i=a; i <= b; i++) {
				String x=i+"";
				for(int j = 1; j < x.length();j++) {
					int status = 0;
					String p =(x.substring(j,x.length()))+x.substring(0,j);
					int num2 = Integer.parseInt(p);
					if(i!=num2 && num2 <= b && num2 >=a) {
						//System.out.println("P VALUE >> " + p);
						//System.out.println("INDEX OF"+x+" : "+vec.indexOf(x));
						for(int k = 0; k < vec.size(); k++) {
							String tmp = (String) vec.elementAt(k);
							String tmp2 = (String) vec2.elementAt(k);
							int c = Integer.parseInt(tmp);
							int d = Integer.parseInt(tmp2);
							if((c == num2 && i == d) || (c==i && d == num2)) {
								status = 1; break;
							}
						}
						if(status == 0) {
							vec.add(x);
							vec2.add(p);
							//System.out.println(">>>"+x+" "+p);
							result++;
						}
					}
				}
			}
		}
		return result;
	}
	
	public static void main(String [] args) {
		File fFile = new File("B.in");
		Scanner scanner = null;
    	try {
    		scanner = new Scanner(new FileReader(fFile));
      		//first use a Scanner to get each line
      		int line = 1;
      		while ( scanner.hasNextLine() ){
        		String name = scanner.nextLine();
        		String []x = name.split(" ");
        		int p1 = Integer.parseInt(x[0]);
        		int p2 = Integer.parseInt(x[1]);
        		System.out.println("Case #"+line+": "+reverse(p1,p2));
        		line++;
      		}
    	}
    	catch(Exception ex) {
    	}
    	finally {
      		scanner.close();
    	}
	}
}