import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
package problemc;

import java.io.BufferedReader;
import java.io.FileReader;

import java.util.ArrayList;
import java.util.List;

public class ProblemC {
    
    public static void main(String args[]){
        List<String> inputs = readInput();
        String n;
        String m;
        int count = 0;
        for(String input : inputs ){
            count++;
            n = input.split(" ")[0];
            m = input.split(" ")[1];
            
            output(count, findRecycledNumbers(n,m));            
        }
    }
    
    
    private static int findRecycledNumbers(String n, String m){
        int recycledNumbers = 0;
        n = n.trim();
        m = m.trim();
        int mFirst = Integer.parseInt(m.substring(0,1));
        int nLong = Integer.parseInt(n);
        int mLong = Integer.parseInt(m);
        String nString = "";
                
        for(int i = nLong; i<mLong; i++){
            nString = ""+i;
            nLong = Integer.parseInt(nString);
            //System.out.println("INTERESTING");
            //System.out.println("I: " + i);
            for(int j=nString.length() - 1; j>0; j--){
               // System.out.println("nSTRING: " + nString);
              String valueAt = nString.substring(j, j+1);
                //System.out.println("VALUE AT: " + valueAt);
                if(Integer.parseInt(valueAt) <= mFirst){
                    //System.out.println("IN HERE");
                    String end = nString.substring(j);
                  String remaining = nString.substring(0, j);
                  String finalNum = end + remaining;
                  
                  
                  if(Integer.parseInt(finalNum) <= mLong && Integer.parseInt(finalNum) > nLong){                      
                    recycledNumbers++;
                  }
                }
            }
        }
        
        
        return recycledNumbers;
    }
  private static List<String> readInput(){
    List<String> untranslatedStrings = new ArrayList<String>();
    try{
        BufferedReader in = new BufferedReader(new FileReader("input.txt"));
        Long numTestCases = Long.parseLong(in.readLine());
        for(int i=0; i<numTestCases.intValue(); i++){
            untranslatedStrings.add(in.readLine());
        }          
    }catch(Exception e){
      e.printStackTrace();
    }
    
    return untranslatedStrings;
  }
  
  private static void output(int input, int recycledNum){
    System.out.println("Case #"+input+": "+recycledNum);
  }
}
