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 code12.qualification;

import java.io.File;
import java.io.FileWriter;
import java.util.HashSet;
import java.util.Scanner;

public class C {
	public static String solve(int A, int B) {
		int output = 0;
		
		for (int i = A; i < B; i++) {
			output += findNumOfRecyclePair(i, A, B);
		}
		
		return "" + output;
	}
	
	public static int findNumOfRecyclePair(int x, int min, int max) {
		int output = 0;
		HashSet<Integer> numSet = new HashSet<Integer>();
		char[] charList = (x + "").toCharArray();
		int[] digitList = new int[charList.length];
		
		for (int i = 0; i < digitList.length; i++) {
			digitList[i] = Integer.parseInt(charList[i] + "");
		}
		
		int num = 0;
		for (int i = 0; i < digitList.length; i++) {
			num = 0;
			for (int j = 0; j < digitList.length; j++) {
				num = num * 10 + digitList[(i + j) % digitList.length];
			}
			
			Integer numInt = new Integer(num);
			if (num > x && num <= max && !numSet.contains(numInt)) {
				numSet.add(numInt);
				output++;
//				System.out.println("(" + x + ", " + num + ")");
			}
		}
		
		return output;
	}

	public static void main(String[] args) throws Exception {
		// file name
		//String fileName = "Sample";
		//String fileName = "C-small";
		String fileName = "C-large";
		
		// file variable
		File inputFile = new File(fileName + ".in");
		File outputFile = new File(fileName + ".out");
		Scanner scanner = new Scanner(inputFile);
		FileWriter writer = new FileWriter(outputFile);

		// problem variable
		int totalCase;
		int A, B;

		// get total case
		totalCase = scanner.nextInt();

		for (int caseIndex = 1; caseIndex <= totalCase; caseIndex++) {
			// get input
			A = scanner.nextInt();
			B = scanner.nextInt();

			String output = "Case #" + caseIndex + ": " + solve(A, B);
			System.out.println(output);
			writer.write(output + "\n");
		}
		scanner.close();
		writer.close();
	}
}
