import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

package _2012.QualificationRound.C;

import java.util.ArrayList;

import Utils.InputFile;
import Utils.OutputFile;

public class C {

	
	
	
	
	private static void solve(InputFile inputFile, OutputFile outputFile){
		
		int nbCases = Integer.parseInt(inputFile.getNextLine());
		
		for(int caseNumber = 0; caseNumber < nbCases; caseNumber++){
			String[] line = inputFile.getNextLine().split(" ");

			int A = Integer.parseInt(line[0]);
			int B = Integer.parseInt(line[1]);
			
			//n != m
			//m don't start with 0
			
			int cptRecycled = 0;
			for (int i =A; i <= B; i++){
				String number = ""+i;
				String recycled = ""+number;
				ArrayList<Integer> recycledList = new ArrayList<Integer>();
				for(int j = 0; j < number.length(); j++){
					recycled = recycled.charAt(recycled.length()-1)+ recycled.substring(0, recycled.length()-1);
					int recycledInt = Integer.parseInt(recycled);
					if(recycledInt >= A && recycledInt <= B && recycledInt != i && !recycledList.contains(recycledInt)){
						cptRecycled++;
						recycledList.add(recycledInt);
					}
				}
			}
			
			
			System.out.println("case " + caseNumber + " on " + nbCases);
			String result = "" +(cptRecycled/2) ;
			
			outputFile.writeResult(result);
			
		}
		
		
		
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public static void main(String[] args) {
		
		InputFile inputFile = new InputFile("C", "large");
		OutputFile outputFile = new OutputFile(inputFile);
		solve(inputFile, outputFile);
		outputFile.endFile();
		
	}
	
	
	
}
