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

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

package gjc.recyclednumber;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

public class Solution {

	List<Integer> list = new LinkedList<Integer>();
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new FileReader("C-large.in"));
		BufferedWriter bw = new BufferedWriter(new FileWriter("C-large.txt"));
		int nTestCases = Integer.parseInt(br.readLine());
		long start = System.currentTimeMillis();
		for (int i=0; i<nTestCases; i++) {
			Set<String> resultSet = new HashSet<String>();
			String line = br.readLine();
			StringTokenizer st = new StringTokenizer(line);
			String bottomStr = st.nextToken();
			int bottom = Integer.parseInt(bottomStr);
			int top= Integer.parseInt(st.nextToken());
			for (int j=bottom; j<=top; j++) {
				// Rotate and check if existing number exists.
				String jStr = j+"";
				String temp = jStr;
				for (int k=0; k<temp.length()-1; k++) {
					temp = temp.substring(1) + temp.charAt(0);
					if (!temp.startsWith("0")) {
						//int number = Integer.parseInt(temp);
						if (temp.compareTo(jStr)<0 && temp.compareTo(bottomStr)>=0) {
							String str = temp+jStr;
							if (!resultSet.contains(str)) {
								resultSet.add(str);
							}
						}
					}
				}
			}
			
			// Display the results.
			bw.write("Case #"+(i+1)+": ");
			bw.write(resultSet.size()+"\n");
		}
		bw.close();
		long end = System.currentTimeMillis();
		System.out.println("Time taken = "+(end-start)+" seconds.");
	}

}
