
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.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class RecycledPairs {

	
	public static void main(String args[]) throws IOException {
		BufferedWriter resultWriter = new BufferedWriter(new FileWriter("C:\\Users\\Andriy\\workspaces\\codejam\\RecycledPairs\\src\\datasetOutput"));
		BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\Andriy\\Downloads\\C-small-attempt0.in"));
		int totalCases = Integer.parseInt(reader.readLine());
		int caseNumber = 0;
		while (++caseNumber <= totalCases) {
			String[] numbers = reader.readLine().split(" ");
			if (numbers.length != 2 || numbers[0].length() == 1) {
				resultWriter.write(String.format("Case #%d: %d\n", caseNumber, 0));
				continue;
			}
			int a = Integer.parseInt(numbers[0]);
			int b = Integer.parseInt(numbers[1]);
			int recycles = 0;
			
			final char[] buffer = new char[numbers[0].length()];
			for (int m = a+1; m <= b; m++) {
				final char[] mChar = String.valueOf(m).toCharArray();
				for (int n=a; n < m; n++) {
					final char[] nChar = String.valueOf(n).toCharArray();
					int length = 0;
					while (++length < mChar.length) {
						// skip leading zeros
						final int pivotPos = nChar.length - length;
						if (pivotPos == '0') {
							continue;
						}
						System.arraycopy(nChar, pivotPos, buffer, 0, length);
						System.arraycopy(nChar, 0, buffer, length, pivotPos);
						
						if (Arrays.equals(buffer, mChar)) {
							recycles++;
							break;
						}
					}
				}
			}
			resultWriter.write(String.format("Case #%d: %d\n", caseNumber, recycles));
		}
		resultWriter.flush();
		resultWriter.close();
	}
}
