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.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class RecycledNumbers {

	private long low;
	private long high;
	private Map<Long, Boolean> map = new HashMap<Long, Boolean>();
	private int recycycled = 0;

	public static void main(String[] args) throws NumberFormatException,
			IOException {

		File file = new File("C:\\Users\\xebia\\Downloads\\C-small-attempt0.in");

		FileInputStream fis = new FileInputStream(file);
		DataInputStream in = new DataInputStream(fis);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		int numberOfTestCases = new Integer(br.readLine());
		for (int j = 0; j < numberOfTestCases; j++) {

			RecycledNumbers re = new RecycledNumbers();
			String[] strings = br.readLine().split(" ");
			String s = strings[0];
			String s2 = strings[1];
			long high = new Long(s2);
			long low = new Long(s);
			int numberOfDigits = s.length();
			for (long i = low; i <= high; i++) {
				int roundOffFigure = 1;
				for (int k = 0; k < numberOfDigits - 1; k++) {
					roundOffFigure = roundOffFigure * 10;
					long lastDigit = (long) (i % roundOffFigure);
					String str = "" + lastDigit;

					if (str.length() == k + 1) {

						long startingCombination = (long) (i / roundOffFigure);
						if (lastDigit == 0) {
							continue;
						}
						long number = (long) (lastDigit
								* (Math.pow(10, numberOfDigits - str.length())) + startingCombination);

						if (number >= low && number <= high) {
							if (number != i) {
								Boolean bool = re.map.get(number * i);
								if (bool == null) {
									re.map.put(number * i, true);
									re.recycycled++;
								}

							}
						}
					}
				}

			}
			System.out.println("Case #" + (j + 1) + ": " + re.recycycled);
		}
	}

	public void setLow(long low) {
		this.low = low;
	}

	public long getLow() {
		return low;
	}

	public void setHigh(long high) {
		this.high = high;
	}

	public long getHigh() {
		return high;
	}

	public void setRecycycled(int recycycled) {
		this.recycycled = recycycled;
	}

	public int getRecycycled() {
		return recycycled;
	}

}
