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 de.johanneslauber.codejam;

import java.io.IOException;

/**
 * 
 * @author Johannes Lauber - joh.lauber@googlemail.com
 * 
 */
public class Main {

	/**
	 * @author Johannes Lauber - joh.lauber@googlemail.com
	 * @param Args
	 */
	public static void main(String[] Args) {
		long millis = System.currentTimeMillis();

		// solveProblem("input/A-small-practice.in", "StoreCredit");
		// solveProblem("input/A-large-practice.in", "StoreCredit");
		// solveProblem("input/B-small-practice.in", "ReverseWords");
		// solveProblem("input/B-large-practice.in", "ReverseWords");
		// solveProblem("input/C-small-practice.in", "T9Spelling");
		// solveProblem("input/C-large-practice.in", "T9Spelling");
		// solveProblem("input/A-small-practice.in", "SpeakinginTongues");
		// solveProblem("input/B-large.in", "DancingGooglers");
		solveProblem("input/C-small-attempt.in", "RecycledNumbers");

		System.out.println(System.currentTimeMillis() - millis);
	}

	/**
	 * 
	 * @author Johannes Lauber - joh.lauber@googlemail.com
	 * @param fileName
	 * @param problemName
	 */
	private static void solveProblem(String fileName, String problemName) {
		CaseProvider caseProvider = new CaseProvider();
		try {
			try {
				caseProvider.importFile(
						fileName,
						Class.forName("de.johanneslauber.codejam.model.impl."
								+ problemName + "Case"));

				caseProvider.solveCases(Class
						.forName("de.johanneslauber.codejam.model.impl."
								+ problemName + "Problem"));
			} catch (ClassNotFoundException e) {
				System.out.println("Error finding implemented Case: "
						+ e.getMessage());
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		} catch (IOException e) {
			System.out.println("Error reading file: " + e.getMessage());
		}
	}
}