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 glycine.gcj2012.qr;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class ProblemC {
	private static Set<String> set = new HashSet<String>();

	private static void countRecycle(String numStr, int min, int max) {
		int num = Integer.valueOf(numStr);

		for (int i = 1; i < numStr.length(); ++i) {
			String frontStr = numStr.substring(0, i);
			String backStr = numStr.substring(i, numStr.length());
			if (backStr.charAt(0) == '0') {
				continue;
			}
			String newNumStr = backStr + frontStr;
			int newNum = Integer.valueOf(newNumStr);
			if (newNum >= min && newNum <= max && newNum > num) {
				// System.out.println( numStr + ", " + newNumStr);
				set.add(numStr + ":" + newNumStr);
			}

		}
		return;
	}

	private static void solve(String minStr, String maxStr) {
		set.clear();
		int min = Integer.valueOf(minStr);
		int max = Integer.valueOf(maxStr);
		int length = minStr.length();
		for (int i = min; i <= max; ++i) {
			String numStr = Integer.toString(i);
			countRecycle(numStr, min, max);

		}

		// System.out.println("result = " + set.size());
	}

	public static void main(String[] args) throws IOException {
		if (args.length != 1) {
			System.err.println("Usage: <program> inputFilename");
			return;
		}
		BufferedReader reader = new BufferedReader(new FileReader(args[0]));
		String line = reader.readLine();
		int times = Integer.parseInt(line);
		for (int i = 0; i < times; ++i) {
			line = reader.readLine();
			String[] tokens = line.split(" ");
			solve(tokens[0], tokens[1]);
			System.out.println("Case #" + (i+1) + ": " + set.size());

		}
	}

}
