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.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

public class ProblemC {
	
	public static void main(String [] args)
	{
		new ProblemC();
	}
	
	public ProblemC()
	{
		try
		{
			String [] inputFiles = { "C-small" };//,"A-large" };
			BufferedReader in;
			PrintWriter out;
			for(int i = 0 ; i < inputFiles.length; i++)
			{
				in = new BufferedReader(new FileReader(inputFiles[i]));
				out = new PrintWriter(new FileWriter(inputFiles[i]+".out"),true);
				
				int numCases = Integer.parseInt(in.readLine());
				int min, max;
				String [] items = null;
				for(int j = 0 ; j < numCases; j++)
				{
					items = in.readLine().split("\\s+");
					min = Integer.parseInt(items[0]);
					max = Integer.parseInt(items[1]);
					int total = 0;
					for(int x = min; x <= max; x++)
					{
						for(int y=x+1; y<= max; y++)
						{
							if(checkReycled(x,y))
								total++;
							
						}
					}
					out.println("Case #" + (j+1) + ": " + total);
				}
				in.close();
				out.close();
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	private boolean checkReycled(int x, int y) {
		if(x == y)
			return false;
		else if(x<10 || y<10)
			return false;
		else if(x>=1000)
			return false;
		
		String xstr = new String("" +x);
		String ystr = new String("" +y);
		if(xstr.length() != ystr.length())
			return false;
		
		if(xstr.length() == 2)
		{
			if(xstr.charAt(0) == ystr.charAt(1) &&
					xstr.charAt(1) == ystr.charAt(0))
				return true;
		}
		else
		{
			if(xstr.charAt(0) == ystr.charAt(1) &&
					xstr.charAt(1) == ystr.charAt(2) &&
					xstr.charAt(2) == ystr.charAt(0))
				return true;
			else if(xstr.charAt(0) == ystr.charAt(2) &&
					xstr.charAt(1) == ystr.charAt(0) &&
					xstr.charAt(2) == ystr.charAt(1))
				return true;
		}
		return false;
	}
}
