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 RecycledNumber;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;

public class RecycledNumber 
{
	public static void main(String[] args) throws IOException
	{
		//open the file
		FileReader reader = new FileReader(args[0]);	   		
		BufferedReader input = new BufferedReader(reader);
		
		FileWriter fOut = new FileWriter("out.txt", false);
		BufferedWriter out = new BufferedWriter(fOut);
			
		//first line is the number of test cases
		int testCases = Integer.parseInt(input.readLine());
					
		for(int i = 0; i < testCases; i++)
		{			
			String line = input.readLine();
			System.out.println(line);
			
			int answer = 0;
			
			String[] ab = line.split(" ");

			int a = Integer.parseInt(ab[0]);	
			int b = Integer.parseInt(ab[1]);
			
			int n = a;
			int m = b;
			
			//figure out the length we are dealing with
			int length = (int)(Math.log10(a)+1);
			
			HashMap<Integer,Integer> matches = new HashMap<Integer,Integer>();
			
			for(int j = n; j < m; j++)
			{
				for(int k = m; k > j; k--)
				{
					//now, shift digits from back of j and compare to k
					String shifter = String.valueOf(j);
					for(int shift = 1; shift < length; shift ++)
					{						
						String front = shifter.substring(0,shift);
						String back = shifter.substring(shift, shifter.length());
						
						//no leading zeroes after shift
						if(!back.startsWith("0"))
						{							
							int shiftedInt = Integer.parseInt(back + front);
							
							//match!
							if(shiftedInt == k 
									&& (!matches.containsKey(shiftedInt) || matches.get(shiftedInt) != j)
									)
							{
								answer++;
								matches.put(shiftedInt, j);							
							}
						}
					}				
				}
			}
						
			out.write("Case #" + (i + 1) + ": " + answer + "\n");
			System.out.println(answer);			
		}
		
		out.close();
	}
}
