package codejam;

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

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}

import java.util.Scanner;
import java.io.File;
import java.util.HashSet;

public class RecycledNumberFinder
 {
 	
 	
 	public void analyzeInputFile(String fileName) throws Exception
 	 {
 	   Scanner fileScanner = new Scanner (new File (fileName) ); 	
 	   
 	   String line;
 	   
 	   line = fileScanner.nextLine();
 	   
 	   int numberOfTestCases = Integer.parseInt(line.trim());
 	   
 	   
 	   
 	   for(int i = 1; i<= numberOfTestCases ; i++)
 	    { 
 	       line = fileScanner.nextLine();	
 	       
 	       Scanner lineScanner = new Scanner(line);
 	       
 	       int A;
 	       int B;
 	       
 	       A = Integer.parseInt(lineScanner.next().trim());
 	       B = Integer.parseInt(lineScanner.next().trim());
 	       
 	      // System.out.println("\n\nA = "+A+" B = "+B);
 	       
 	       HashSet<String> set = new HashSet<String>();
 	       
 	       int num;
 	       
 	       for(num = A; num<=B ; num ++)
 	        {
 	           int powerOfTenForNum;
 	           
 	           powerOfTenForNum = getPowerOfTenForNumber(num);
 	           
 	           int P = powerOfTenForNum+1;
 	           
 	           for(int power=1; power<= powerOfTenForNum; power++)
 	            {
 	               int Q;
 	               int R;
 	               int n,m;
 	               
 	               Q = num / (int) (Math.pow(10,power));
 	               R = num % (int) (Math.pow(10,power));
 	               P--;
 	               
 	               int newNumberFormed = (int) (Math.pow(10,P)) * R + Q;
 	              
 	               
 	               if(newNumberFormed < A || newNumberFormed >B)
 	                {
 	                   // it is bad.
 	                   continue;	
 	                }	
 	               
 	               if(newNumberFormed == num)
 	                {
 	                   // no use 	
 	                   continue;	
 	                } 
 	               
 	               if(newNumberFormed < num)
 	                {
 	                   n = newNumberFormed;
 	                   m = num;	
 	                }  
 	               else
 	                {
 	                   n = num;
 	                   m = newNumberFormed; 	
 	                } 
 	               
 	               String entryIntoSet = new String("("+n+","+m+")");
 	                
 	               //System.out.printf("(%d,%d) ",num,newNumberFormed); 
 	              // System.out.print(entryIntoSet+" ");
 	               set.add(entryIntoSet);
 	            }
 	           
 	        }
 	       
 	      // System.out.println("\nNo = "+set.size()+"\n");
 	       System.out.println("Case #"+i+": "+set.size());
 	    }	 	
 	 }
 	
 	private int getPowerOfTenForNumber(int num)
 	 {
 	   	int powerOfTenForNum;
 	           
 	    int Q=-1;
 	    int power = -1;
 	           
 	    while(Q!=0)
 	     {
 	       power++;
 	       Q = num / (int) (Math.pow(10,power));	
 	     }	
 	           
 	     
 	    powerOfTenForNum = power-1;
 	     
 	    return powerOfTenForNum;      
 	 }
 	
 	
    public static void main(String[] args) throws Exception
     {
     	RecycledNumberFinder RNF = new RecycledNumberFinder(); 
     	String inputFile = "C-small-attempt0.in";
     	
     	RNF.analyzeInputFile(inputFile);
     }	
 	
 }