package codejam;

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

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}

package hk.polyu.cslhu.codejam.thread;

import hk.polyu.cslhu.codejam.lib.ResultCollector;
import hk.polyu.cslhu.codejam.solution.Solution;

import java.util.List;

import org.apache.log4j.Logger;

public abstract class JamThread implements Runnable {
	public static Logger logger = Logger.getLogger(JamThread.class);

	private ResultCollector resultCollector;
	private int indexOfList;
	private List<List<String>> testCaseList;
	private Solution solution;
	
	/**
	 * Return the solution
	 * 
	 * @return Solution
	 */
	public Solution getSolution() {
		return solution;
	}

	/**
	 * Set the solution used for test cases
	 * 
	 * @param solution Solution
	 */
	public void setSolution(Solution solution) {
		this.solution = solution;
	}

	/**
	 * Return the result collector
	 * 
	 * @return ResultCollector
	 */
	public ResultCollector getResultCollector() {
		return resultCollector;
	}

	/**
	 * Set the result collector
	 * 
	 * @param resultCollector ResultCollector
	 */
	public void setResultCollector(ResultCollector resultCollector) {
		this.resultCollector = resultCollector;
	}
	
	/**
	 * Return the index of list
	 *  
	 * @return int The index of list
	 */
	public int getIndexOfList() {
		return indexOfList;
	}

	/**
	 * Set the index of list
	 * 
	 * @param indexOfList int The index of list
	 */
	public void setIndexOfList(int indexOfList) {
		this.indexOfList = indexOfList;
	}

	/**
	 * Set the list of test cases
	 * 
	 * @param testCaseList List<LIst<String>>
	 */
	public void setTestCaseList(List<List<String>> testCaseList) {
		this.testCaseList = testCaseList;
		logger.debug("Total " + testCaseList.size() + " test cases have been added");
	}
	
	/**
	 * Get the list of test cases
	 * 
	 * @return List<List<String>> The list of test cases
	 */
	public List<List<String>> getTestCaseList() {
		return this.testCaseList;
	}
	
	public abstract void run();
}
