import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

// Recycled Numbers
// https://code.google.com/codejam/contest/1460488/dashboard#s=p2

public class C {

	private static String process(Scanner in) {
		int A = in.nextInt();
		int B = in.nextInt();
		int res = 0;
		int len = Integer.toString(A).length();
		for(int n = A; n < B; n++) {
			String str = Integer.toString(n);
			TreeSet<Integer> set = new TreeSet<Integer>();
			for(int i = 1; i < len; i++) {
				int m = Integer.parseInt(str.substring(i, len) + str.substring(0, i));
				if ( m > n && m <= B && ! set.contains(m) ) {
					set.add(m);
					res++;
				}
			}
		}
		return Integer.toString(res);
	}

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in.available() > 0 ? System.in : 
			new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + ".practice.in"));
		int T = in.nextInt();
		for(int i = 1; i <= T; i++) 
			System.out.format("Case #%d: %s\n", i, process(in));
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;


public class recycle {
	static int count=0;
	static int A = 0;
	static int B = 0;
	
	public static void permutes(String start){
		int n = Integer.valueOf(start);
		for(int i=1;i<start.length();i++){
			String current = start.substring(0, i);
			String rest = start.substring(i, start.length());
			String finish = rest+current;
			int m = Integer.valueOf(finish);
			if(n==m){
				break;
			}
				
			if(m<=B && n<m){
				count++;
			
			}
		}
		
	}
	public static void main(String args[])
	 {
		String line;
		  int i=0;
		  try{
		  FileInputStream fstream1 = new FileInputStream("Ctest.txt");
		  DataInputStream in1 = new DataInputStream(fstream1);
		  BufferedReader br1 = new BufferedReader(new InputStreamReader(in1));
		  FileWriter fw = new FileWriter("outC.txt");
		  BufferedWriter out = new BufferedWriter(fw);
		 
		  while ((line = br1.readLine()) != null)   {  
		  		

		  		if(i!=0){
		  			String outpt = "Case #"+i+": ";
		  			String brkline[]=line.split(" ");
		  			A = Integer.valueOf(brkline[0]);
		  			//System.out.println("A= "+A);
		  			B = Integer.valueOf(brkline[1]);
		  			//System.out.println("B= "+B);
		  			
		  			for(int p=A;p<=B;p++){
		  				permutes(String.valueOf(p));
		  			}
		  			outpt = outpt+count;		
		  			out.write(outpt+"\n");
		  			System.out.println(outpt);
		  			}
		  		
		  		i++;
		  		count=0;
		  	  }
		  
		  //Close the input stream
		  in1.close();
		  //Close the output stream
		  out.close();
		    }catch (Exception e){//Catch exception if any
		  System.err.println("Error: " + e);
		  }
/////////////////////////////////////////////////				
		
	 }
}
