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 codejam;

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

public class Qual2012C {
	private static int digitCount;
	private static int[] MULTIPLES = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000 };

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int nrOfTestCases = scanner.nextInt();
		for (int caseNr = 1; caseNr <= nrOfTestCases; caseNr++) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			digitCount = digitCount(a);
			System.out.println("Case #" + caseNr + ": " + solve(a, b));
		}
	}

	private static int digitCount(int a) {
		if (a == 0)
			return 0;
		return 1 + digitCount(a / 10);
	}

	private static long solve(int min, int max) {
		long total = 0;
		for (int n = min; n < max; n++)
			total += pairsFor(n, max);
		return total;
	}

	private static int pairsFor(int n, int max) {
		if (n >= max)
			return 0;
		HashSet<Integer> set = new HashSet<Integer>();
		for (int i = 1; i < digitCount; i++) {
			int multipleSplit = MULTIPLES[i];
			int tail = n % multipleSplit;
			if (tail < MULTIPLES[i - 1])
				continue;
			int m = tail * MULTIPLES[digitCount - i] + (n / multipleSplit);
			if (n < m && m <= max)
				set.add(m);
		}
		return set.size();
	}
}
