import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

// Recycled Numbers
// https://code.google.com/codejam/contest/1460488/dashboard#s=p2

public class C {

	private static String process(Scanner in) {
		int A = in.nextInt();
		int B = in.nextInt();
		int res = 0;
		int len = Integer.toString(A).length();
		for(int n = A; n < B; n++) {
			String str = Integer.toString(n);
			TreeSet<Integer> set = new TreeSet<Integer>();
			for(int i = 1; i < len; i++) {
				int m = Integer.parseInt(str.substring(i, len) + str.substring(0, i));
				if ( m > n && m <= B && ! set.contains(m) ) {
					set.add(m);
					res++;
				}
			}
		}
		return Integer.toString(res);
	}

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in.available() > 0 ? System.in : 
			new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + ".practice.in"));
		int T = in.nextInt();
		for(int i = 1; i <= T; i++) 
			System.out.format("Case #%d: %s\n", i, process(in));
	}
}

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();
}
