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

			}
		}

	}
}

import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.io.*;

public class RecycledNumbers {

	private final static String FILE_IN = RecycledNumbers.class.getSimpleName() + ".in";			
	private final static String FILE_OUT = RecycledNumbers.class.getSimpleName() + ".out";			
	
	public static void main(String[] args) throws Exception {
		final Scanner in = new Scanner(new File(FILE_IN));
		final PrintWriter out = new PrintWriter(FILE_OUT);
		final int testCnt = in.nextInt();
		for (int caseNum = 1; caseNum <= testCnt; ++ caseNum){
			final int a = in.nextInt();
			final int b = in.nextInt();			
			final int last [] = new int [b + 1];
			int result = 0;
			for (int i = a; i <= b; ++ i){
				final String s = String.valueOf(i);			
				for (int pos = 1; pos < s.length(); ++ pos){
					final String newNum = s.substring(pos) + s.substring(0, pos);
					final int newInt = Integer.valueOf(newNum);
					if (newInt > i && newInt <= b){
						if (last[newInt] != i){
							++ result;
							last[newInt] = i;
						}
					}
				}
			}
			out.println(String.format("Case #%d: %d", caseNum, result));
		}
		in.close();
		out.close();
	}

}
