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

	}
	
	
}
import java.util.Collection;
import java.util.ArrayList;
import java.util.Arrays;
import java.lang.Integer;
import java.io.*;
import java.util.Scanner;

public class RecycledNumbers{

  private long inversions = 0;
  
  public static void main(String[] args) throws FileNotFoundException{
    String filename = args[0];
    RecycledNumbers countInversions = new RecycledNumbers();
    countInversions.readArray(filename);
//    list = countInversions.sortAndCount(list);
//    System.out.println(list);
//    System.out.println(countInversions.inversions);
  }
  
  private void readArray( String filename ) throws FileNotFoundException{
    ArrayList<Integer> list = new ArrayList<Integer>();
    File fFile = new File(filename);
    Scanner scanner = new Scanner(new FileReader(fFile));
    try {
      BufferedWriter out = new BufferedWriter(new FileWriter("outfilename"));
      int k = Integer.valueOf(scanner.nextLine());
      for (int j=1; j<=k; ++j){
        String szoveg = scanner.nextLine();
        Object[] szamok =szoveg.split("[^0-9]");
        int A = Integer.valueOf((String)szamok[0]);
        int B = Integer.valueOf((String)szamok[1]);

        String mashogy = new String();

        mashogy = mashogy.concat("Case #");
        mashogy = mashogy.concat(((Integer)j).toString());
        mashogy = mashogy.concat(": ");


        int s=0;
        for (int i=A; i<B; ++i){
          int l = ((Integer)A).toString().length();
//          System.out.println(l);
          ArrayList<Integer> elerh = new ArrayList<Integer>();
          for (int f=1; f<l; ++f){
            int pow = (int)Math.floor(Math.pow(10,f));
            int powpot = (int)Math.floor(Math.pow(10,l-f));
            int ael = i/pow;
            int aveg = i%pow;
            int ford = powpot*aveg+ael;
            if (ford>i && ford<=B && !elerh.contains(ford)){
//              System.out.println(pow+" "+ael+" "+aveg+" "+ford);
              elerh.add(ford);
              s++;
            }
          }
        }
//      String mashogy = (String)(szoveg.clone());
//      System.out.println(szoveg);
        mashogy = mashogy.concat(((Integer)s).toString());
        mashogy = mashogy.concat("\n");
        out.write(mashogy);
      }    
      out.close();
    } catch (IOException e) {
    }
    scanner.close();
    return;
  }
}
