package codejam;

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

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}

package contest;

import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Input {
	BufferedReader in;

	public Input(BufferedReader in) {
		this.in = in;
	}

	//

	public String readStr() {
		return readStr(in);
	}

	public int readInt() {
		return readInt(in);
	}

	public int[] readIntArr() {
		return readIntArr(in, " ");
	}

	public List<Integer> readIntList() {
		return readIntList(in, " ");
	}

	public List<String> readStrList() {
		return readStrList(in, " ");
	}

	//

	public String readStr(BufferedReader in) {
		try {
			return in.readLine();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public int readInt(BufferedReader in) {
		return Integer.parseInt(readStr(in));
	}

	public int[] readIntArr(BufferedReader in) {
		return readIntArr(in, " ");
	}

	public int[] readIntArr(BufferedReader in, String delimiter) {
		String[] tokens = readStr(in).split(delimiter);
		int[] ints = new int[tokens.length];
		for (int i = 0; i < tokens.length; i++) {
			ints[i] = Integer.parseInt(tokens[i]);
		}
		return ints;
	}

	public List<Integer> readIntList(BufferedReader in) {
		return readIntList(in, " ");
	}

	public List<Integer> readIntList(BufferedReader in, String delimiter) {
		String[] tokens = readStr(in).split(delimiter);
		List<Integer> ints = new ArrayList<Integer>(tokens.length);
		for (int i = 0; i < tokens.length; i++) {
			ints.add(Integer.parseInt(tokens[i]));
		}
		return ints;
	}

	public List<String> readStrList(BufferedReader in, String delimiter) {
		return Arrays.asList(readStr(in).split(delimiter));
	}
}
