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

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

public class CodeJamC
{

	private static int noOfDigits(int number)
	{
		int noOfDigits = 0;
		while (number > 0)
		{
			number /= 10;
			noOfDigits++;
		}
		return noOfDigits;
	}

	private static int pow(int exponent)
	{
		int power = 1;
		for (int mulitply = 1; mulitply <= exponent; mulitply++)
			power *= 10;
		return power;
	}

	private static int countPairs(int A, int B)
	{

		int noOfDigits = noOfDigits(A);
		int noOfPairs = 0;
		int places = pow(noOfDigits);
		for (int next = A; next < B; next++)
		{
			HashSet<Integer> used = new HashSet<Integer>();
			// System.out.println("Next "+ next);
			for (int back = 10; back < places; back *= 10)
			{
				int recycled = shift(next, back, places / back);
				// System.out.println("Back: " + back + "RC " + recycled);
				if (recycled > next && recycled <= B)
				{
					// System.out.println(next +", " + recycled);
					if (!used.contains(recycled))
					{
						used.add(recycled);
						noOfPairs++;
					}
				}
			}
		}

		return noOfPairs;
	}

	private static int shift(int number, int back, int front)
	{
		return (number % back) * front + number / back;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException
	{
		String fileName = "C-small0";
		Scanner in = new Scanner(new File(fileName + ".in"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				fileName + ".out")));

		// Keep track of time for efficiency
		long startTime = System.currentTimeMillis();
		// Process each of the test cases
		int noOfCases = in.nextInt();

		for (int caseNo = 1; caseNo <= noOfCases; caseNo++)
		{
			int A = in.nextInt();
			int B = in.nextInt();

			int noOfPairs = countPairs(A, B);

			System.out.println("Case #" + caseNo + ": " + noOfPairs);
			out.println("Case #" + caseNo + ": " + noOfPairs);
		}

		System.out.println("Done");
		long stopTime = System.currentTimeMillis();
		System.out.println("Time: " + (stopTime - startTime) / 1000.0);

		// Close the files
		in.close();
		out.close();
	}
}
