/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package recyclednumbers;

import java.util.HashSet;

/**
 *
 * @author vandit
 */
public class RecycleNumbers {

    private HashSet<String> numbers = new HashSet<String>();
    private HashSet<String> initialTempNumbers = new HashSet<String>();
    private HashSet<String> finalTempNumbers = new HashSet<String>();

    HashSet<Pair> numberPairs = new HashSet<Pair>();


    private void findRecycledNumbers(int start, int end, int places) {


        for (int i = start; i <= end; i++) {
            String initialNumber = Integer.toString(i);
            //if (!(numbers.contains(initialNumber) || finalTempNumbers.contains(initialNumber))) {

                StringBuffer tempNumber = new StringBuffer(initialNumber);
                int len = tempNumber.length();
                int startIndexToMove = len - places;
                String tempString = tempNumber.substring(startIndexToMove);
                if ((places == 1 && tempString.equals("0")) || tempString.charAt(0) == '0') {
                    continue;
                }
                tempNumber.delete(startIndexToMove, len);
                String finalTempNumber = tempString + tempNumber.toString();

                if (! (finalTempNumber.equals(initialNumber) || Integer.parseInt(finalTempNumber) > end || Integer.parseInt(finalTempNumber) < Integer.parseInt(initialNumber))) {
                    numbers.add(initialNumber);
                    finalTempNumbers.add(finalTempNumber);
                    Pair pair = new Pair(finalTempNumber,initialNumber);
                    numberPairs.add(pair);
                }
            }

        

    }

    public HashSet<Pair> findAllRecycledNumbers(int start, int end) {
        int length = Integer.toString(start).length();
        for (int i = 1; i < length; i++) {
            findRecycledNumbers(start, end, i);
        }
        return numberPairs;
    }
}

import java.util.*;
import java.io.*;


public class probC {
	public static void main (String args[]) throws IOException
	{
		BufferedReader in = new BufferedReader(new FileReader("C:\\downloads\\c-small-attempt0.in"));
		BufferedWriter out = new BufferedWriter(new FileWriter("C:\\downloads\\c-small-output.in"));
		int t = Integer.parseInt(in.readLine());
		int i,j,k,l;
		int A,B;
		int len;
		int count;
	    for (i=1;i<=t;i++)
		{ StringTokenizer st = new StringTokenizer(in.readLine());
		  A = Integer.parseInt(st.nextToken());
		  B = Integer.parseInt(st.nextToken());
		  count=0;
		  len = String.valueOf(A).length();
		  int[] temp =  new int[len];
		  for (j=A;j<=B;j++)
		  { String n;
		    n = String.valueOf(j);
		    
		    for (k=0;k<len-1;k++)
		    { int flag=0;
		      temp[k] = Integer.parseInt(n);
		      StringBuilder sb = new StringBuilder();
		    	for (l=1;l<len;l++)		         
		          sb.append(n.charAt(l));
		    	sb.append(n.charAt(0));
		    	int y = Integer.parseInt(sb.toString());
		    	for (int x : temp)
		    		if (x==y)
		    		{ flag=1;
		    		  break;
		    		}
		    	if ((flag==0) && (y>j) && (y<=B))
		    			count++;
		    	n = sb.toString();
		  }
		    }
		out.write("Case #"+i+": "+count);
		out.newLine();
		  
		}
		  out.close();
	}

}
