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.io.*;
   import java.util.*;
   
    public class ProblemB {
   
       public static void main(String[] args) throws Exception {
      
         String filename = "C-small-attempt0.in";
         Scanner sc = new Scanner(new File(filename) );
      
         System.setOut(new PrintStream(new FileOutputStream("BSolution.txt")));
         int cases = Integer.parseInt(sc.next());
         sc.nextLine();
         
         for(int l = 1; l <= cases; l++) {
          	  
            int A = sc.nextInt();
            int B = sc.nextInt();
            
            int counter = 0;	
            
            for(int m = B; m > A; m--) {
            
               for(int n = A; n < m; n++) {
               
                  if(isRecycled(n,m))
                     counter++;
               }
            }
         	
            System.out.print("Case #" + l + ": " + counter);
            System.out.println();
         }
      }
       public static boolean isRecycled(int n, int m) {
      
         String str = Integer.toString(n);
      	
         if(Integer.toString(n).length() != Integer.toString(m).length()) 
            return false;
         else {
            for(int k = 1; k < str.length(); k++) {
               String temp = "";
                  
               temp = str.substring(str.length() - k, str.length()) + str.substring(0, str.length() - k);
                 
               if(m == Integer.parseInt(temp))
                  return true;
               
            } 
         }
         return false;
      }
   }