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);
	}
}

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

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 *
 * @author Muhammad Zahran
 */
public class recycleNumber 
{
     public static void main(String[] args) throws IOException 
    {
        PrintWriter w =  new PrintWriter(new FileWriter("out.txt"));
        BufferedReader r = new BufferedReader(new FileReader("input.txt")); 
        int testcases = Integer.parseInt(r.readLine());
        for (int i = 0; i < testcases; i++) 
        {
            int result=0;
            
            String[] tokens = r.readLine().split(" "); 
            String strA = tokens[0];
            int a = Integer.parseInt(tokens[0]);
            int b = Integer.parseInt(tokens[1]);            
            String strB = tokens[1];
            
            int currentNo = a;
            while(true)
            {                      
                if(currentNo > b)
                    break;
                int scratch = currentNo;             
                String strScratch = String.valueOf(currentNo);
                
                for (int d = 1; d < strScratch.length(); d++) 
                {
                     String sub1 = strScratch.substring(strScratch.length()-d,strScratch.length()); //LSD
                     String sub2 = strScratch.substring(0,strScratch.length()-d); //MSD
                     
                    if(!sub1.substring(0, 1).equals("0"))
                    {
                        String strRotated = sub1+sub2;
                        if(!strRotated.equals(strScratch))
                        {
                            int rotated = Integer.parseInt(strRotated);
                            if(rotated <= b && rotated > scratch)
                            {
                              //  w.println(scratch + " : "+rotated);
                               // System.out.println(scratch + " : "+rotated); 
                                result++;
                            }
                        }                    
                    }        
                }
                      
               currentNo++;               
            }
              int asd = i+1;
              w.println("Case #" + asd + ": " + result);
              System.out.println("Case #" + asd + ": " + result);                                  
        }
        
         w.close();
    }
    
}
