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

	}
	
	
}
/*
 * Google Code Challenge Java
 * 
 * Code written for the Google Code Challenge by Greg Dougherty
 * Created: May 7, 2011
 * 
 * Copyright 2011 by Greg Dougherty
 */

package com.google.GregTD.CodeJam2012.Recycled;

import java.io.*;

/**
 * @author Greg Dougherty
 *
 */
public class Recycled
{
	
	private static final String	kInSuffix = ".in";
	private static final String	kOutSuffix = ".out";
	
	/**
	 * @param args
	 */
	public static void main (String[] args)
	{
		String	inName = args[0];
		int		nameLen = inName.indexOf (kInSuffix);
		String	outName = inName.substring (0, nameLen) + kOutSuffix;
		File	dataFile = new File (args[0]);
		File	resultFile = new File (outName);
		
		try
		{
			BufferedReader	dataReader = new BufferedReader (new FileReader (dataFile));
			BufferedWriter	dataWriter = new BufferedWriter (new FileWriter (resultFile));
			String			line = dataReader.readLine ();	// Get first line
			int				numCases = Integer.valueOf (line).intValue ();
			
			// Run each test case
			for (int i = 0; i < numCases; ++i)
			{
				// Get data
				line = dataReader.readLine ();
				
				String[]	entries = line.split (" ");
				int	minValue = new Integer (entries[0]).intValue ();
				int	maxValue = Integer.valueOf (entries[1]).intValue ();
				int	numPairs = 0;
				for (int j = minValue; j <= maxValue; ++j)
				{
					String	str = "" + j;
					int		strLen = str.length ();
					if (strLen < 2)
						continue;
					
					--strLen;
					for (int k = 0; k < strLen; ++k)
					{
						str = str.charAt (strLen) + str.substring (0, strLen);
						int	value = Integer.valueOf (str).intValue ();
						if ((value > j) && (value <= maxValue))
							++numPairs;
					}
				}
				
				dataWriter.write ("Case #" + (i + 1) + ": " + numPairs);
				dataWriter.newLine ();
				dataWriter.flush ();
			}
		}
		catch (IOException ioE)
		{
			ioE.printStackTrace ();
		}
	}
	
}
