
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;

public class Recycle
{
	public static void main(String[] args)
	{
/*		Set<Integer> perms = getPermutations(123456);
		
		for(Integer i: perms)
			System.out.println(i);*/
	
		try
		{
			Scanner s = new Scanner(new File("recycle.in"));
			BufferedWriter w = new BufferedWriter(new FileWriter(new File("recycle.out")));
			int numCases = s.nextInt();
			s.nextLine();
			
			for(int n = 1;n <= numCases; n++)
			{
				int A = s.nextInt();
				int B = s.nextInt();
				int count = 0;
				for(int k = A; k <= B; k++)
				{
					count += getNumPairs(k, B);
				}
				
				w.write("Case #" + n + ": " + count + "\n");
			}
			
			w.flush();
			w.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public static int getNumPairs(int n, int B)
	{
		Set<Integer> possibles = getPermutations(n);
		int count = 0;
		for(Integer i : possibles)
			if(i > n && i <= B)
				count++;
		return count;
	}
	
	public static Set<Integer> getPermutations(int n)
	{
		Set<Integer> perms = new TreeSet<Integer>();
		char[] digits = String.valueOf(n).toCharArray();
		
		for(int firstPos = 1; firstPos < digits.length; firstPos++)
		{
			String toBuild = "";
			for(int k = 0; k < digits.length; k++)
				toBuild += digits[(firstPos + k) % digits.length];
			perms.add(Integer.parseInt(toBuild));
		}
		return perms;
	}
	

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SmallMain 
{
	public static void main( String arg[] )
		throws IOException
	{
		BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
		String line = null;
		int test = 0;
		int testCases = 0;
		while( ( line = reader.readLine() ) != null && test <= testCases )
		{
			if( line != null && !line.isEmpty() )
			{
				String tokens[] = line.split( " " );
				if( tokens.length == 1 && testCases == 0 )
				{
					testCases = Integer.parseInt( tokens[ 0 ] );
				}
				else if( tokens.length == 2 )
				{
					++test;
					int start = Integer.parseInt( tokens[ 0 ] );
					int end = Integer.parseInt( tokens[ 1 ] );
					int counter = 0;
					for( int i = start; i <= end; ++i )
					{
						for( int j = start; j <= end; ++j )
						{
							if( i < j )
							{
								for( int s = 1; s < ( "" + j ).length(); ++s )
								{
									if( i == moveDigits( j, s ) )
									{
										++counter;
										break;
									}
								}
							}
						}
					}
					System.out.println( "Case #" + ( test ) + ":  "+ counter );
				}
				else
				{
					System.out.println( "Invalid length: " + tokens.length + " line: " + line );
				}
			}
		}
		reader.close();
	}
	
	private static int moveDigits( int number, int digits )
	{
		int r;
		String n = "" + number;
		String end = n.substring( n.length() - digits );
		String start = n.substring( 0, n.length() - digits );
	//	System.out.println( "N: " + number + " d: " + digits + " start: " + start + " end: " + end );
		r = Integer.parseInt( end + start );
		return r;
	}
}
