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 gcj.cases.competition.qualification_round_2012;

import gcj.main.Case;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.HashSet;
import java.util.Set;

public class CaseC implements Case{
	
	private int caseNum;
	private long min;
	private long max;
	private long solution;
	

	@Override
	public void init(int caseNum, BufferedReader br) throws Exception {
		String strLine;
		{
			//caseNum
			this.caseNum = caseNum;
			System.out.println("Act case: " + this.caseNum);
		}
		{
			//param 1, min max
			if ((strLine = br.readLine()) != null){
				String[] p = strLine.split(" ");
				min = Long.parseLong(p[0]);
				max = Long.parseLong(p[1]);
			}else{
				throw new Exception("Wrong input");
			}
		}
	}

	
	@Override
	public void solve() throws Exception {
		solution=0l;
		for(long nIter = min; nIter<max; nIter++){
			String nValue = "" + nIter;
			Set<Long> mPairs = new HashSet<Long>();
			for(int i=0; i<nValue.length()-1; i++){
				String nRecicled = nValue.substring(i+1) + nValue.substring(0, i+1);
				long m = Long.parseLong(nRecicled);
				if(m>nIter && m<=max && !mPairs.contains(m)){
					solution++;
					mPairs.add(m);
				}
			}
		}
	}
	
	
	@Override
	public void generateOutput(BufferedWriter bw, boolean needBR) throws Exception {
		bw.write("Case #" + this.caseNum + ": " + this.solution);
		if(needBR){
			bw.newLine();
		}
	}


}
