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 pl.helman.codejam.recycled;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

//Brute force attempt
public class Recycled {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {

		FileReader fr = new FileReader("d:\\recycled.in");
		BufferedReader br = new BufferedReader(fr);
		String s = br.readLine();

		FileWriter f0 = new FileWriter("d:\\recycled.out");

		int t = Integer.parseInt(s.trim());

		for (int i = 1; i <= t; i++) {
			s = br.readLine();
			String[] elems = s.split(" ");
			int a = Integer.parseInt(elems[0]);
			int b = Integer.parseInt(elems[1]);

			int digs = 1;
			int mod = 1;

			int ret = 0;

			while (a >= mod * 10) {
				digs++;
				mod *= 10;
			}

			for (int n = a; n <= b; n++) {
//				System.out.println("  n:"+n);
				int m = n;
				m = (m % mod) * 10 + (m / mod);
				while (m != n) {
				
//					System.out.print("    m:" + m);
					if (m > n && m <= b) {
						ret++;
//						System.out.print(" +");
					}
//					System.out.println();
					
					m = (m % mod) * 10 + (m / mod);
				}

			}

			System.out.println("Case #" + i + ": " + ret);
//			System.out.println();

			f0.write("Case #" + i + ": " + ret + "\r\n");
		}

		fr.close();
		f0.close();

	}

}
