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

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
package szarfos;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Main {
	private static List<String[]> numbers;
	
	public static void main(String[] args) throws IOException {
		readFile();
		BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));
		for (int i = 0; i < numbers.size(); i++) {
			int bound1 = Integer.parseInt(numbers.get(i)[0]);
			int bound2 = Integer.parseInt(numbers.get(i)[1]);
			int c = 0;
			for (int n1 = bound1; n1 <= bound2; n1++) {
				List<Integer> recs = generateRec(Integer.toString(n1));
				for (Integer r : recs) {
					if (r <= bound2 && r >= bound1) {
						c++;
					}
				}
			}
			
			System.out.println("Number of rec nums: " + c/2);
			int caseNum = i+1;
		    out.write("Case #" + caseNum + ": " + c/2);		
		    out.newLine();
		}	
		out.close();
	}		
	
	public static List<Integer> generateRec(String n) {
		List<Integer> recs = new ArrayList<Integer>();
		for (int i = 0; i < n.length()-1; i++) {
			String newNum = changeNumber(n, i);
			if (!newNum.equals(n)) {
				recs.add(Integer.parseInt(changeNumber(n, i)));
			}
		}
		
		return recs;
	}
	
	public static void readFile() {
		try {
			numbers = new ArrayList<String[]>();
		    BufferedReader in = new BufferedReader(new FileReader("input.txt"));
		    String str;
		    in.readLine();
		    while ((str = in.readLine()) != null) {
		    	String[] n = str.split(" ");
		    	numbers.add(n);
		    }
		    in.close();
		} catch (IOException e) {
		}
	}
	
	public static boolean isRecNums(String n, String m) {
		if (n.length() != m.length())
			return false;
		
		if (n.equals(m))
			return false;
		
		for (int i = 0; i < n.length()-1; i++) {
			if (changeNumber(n, i).equals(m)) {
				return true;
			}
		}
		return false;
	}
	
	public static String changeNumber(String n, int k) {
		String tmp = n.substring(n.length()-1-k, n.length());
		n = tmp + n.substring(0, n.length()-1-k);
		
		return n;
	}
	

}
