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));
			
		}
		
		
		

	}
	
	
}
package contests.GoogleCodejam.GCJ2012.qualification;


import contests.GoogleCodeJam.practice.GCJ2010.qualification.ProblemA;

import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: vassili
 * Date: 4/14/12
 * Time: 1:12 PM
 *
 */
public class ProblemC {
    public static void main(String args[]) throws FileNotFoundException {
        Scanner scanner = new Scanner(ProblemC.class.getResourceAsStream("c_small.in"));

        int tests = scanner.nextInt();

        for (int test = 1; test <= tests; test++) {
            int A = scanner.nextInt();
            int B = scanner.nextInt();

            int result = 0;

            for(int i = A; i <= B; i++){
                String num1 = ""+i;
                int len1 = num1.length();

                for(int j = i + 1; j<=B; j++){
                    String num2 = "" + j;
                    if(len1 != num2.length()){
                        break;
                    }

                    for(int k = 0; k < num2.length(); k++){
                        num2 = num2.charAt(len1-1) + num2.substring(0, len1-1);
                        if(num2.equals(num1)){
                            result+=1;
                            break;
                        }
                    }
                }
            }

            System.out.println("Case #" + test + ": " + result);
        }

    }
}

