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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

import javax.swing.plaf.basic.BasicBorders.SplitPaneBorder;

public class C {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		in.nextLine();
		for (int testcase = 1; testcase <= T; testcase++) {
			int A = in.nextInt();
			int B = in.nextInt();
			//System.out.println("["+A + " " + B+"]");
			int answer = 0;
			List<Integer> found = new ArrayList<Integer>();
			for (int i = A; i <= B; i++) {
				for (int j = A; j <= B; j++) {
					if (i < j) {
						for (int k = 1; k < String.valueOf(A).length(); k++) {
							int a, b1;
							String b;
							
							a = recycleNumber(j, k);
							b =  debugsplit(j, k);
							b1 = i;

							if (a == b1) {
								answer += 1;
								//System.out.println(j + " " + b1+ " ["+b+"]");
								
							}
						}
					}
				}

			}
			System.out.format("Case #%d: %s\n", testcase, answer);
		}

	}

	private static int recycleNumber(int num, int pos) {
		String input = String.valueOf(num);
		String subA, subB;

		subA = input.substring(0, pos);
		subB = input.substring(pos);

		/*if(subA == subB){
			return 0;
		}*/
		int result = Integer.parseInt(subB + subA);
		return result;
	}
	private static String debugsplit(int num, int pos) {
		String input = String.valueOf(num);
		String subA, subB;

		subA = input.substring(0, pos);
		subB = input.substring(pos);

		/*if(subA == subB){
			return "";
		}*/
		String result = subA +" "+ subB;
		return result;
	}

}
