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.HashSet;
import java.util.Scanner;
import java.util.Set;

public class C {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		Set<String> recycled = new HashSet<String>();
		
		int T = in.nextInt();

		in.nextLine();

		for (int i = 1; i <= T; i++) {
			int A = in.nextInt();
			int B = in.nextInt();
			int res = 0;
			String n1,n2,n3;
			
			for (int j = A; j <= (B - 1); j++) {
				String n = Integer.toString(j);
				for (int k = 1; k<n.length(); k++){
					n1 = n.substring(k);
					n2 = n.substring(0, k);
					n3 = n1+n2;
					if (Integer.parseInt(n3) > j && Integer.parseInt(n3) <= B && !recycled.contains(n3)){
						recycled.add(n3);
						res++;
					}
				}
				recycled.clear();
			}
			
			System.out.println("Case #"+i+": "+res);
		}

	}
	
//	public static boolean checkRecycled (int n, int m){
//		boolean res = false;
//		
//		String sn = Integer.toString(n);
//		String sm = Integer.toString(m);
//		String snTemp,snTemp2,snTemp3;
//		if (n>10 && (sn.length() == sm.length())){
//			for (int i = 1; i<sn.length(); i++){
//				snTemp = sn.substring(i);
//				snTemp2 = sn.substring(0, i);
//				snTemp3 = snTemp+snTemp2;
//				if (snTemp3.equals(sm))
//					return true;
//			}
//		}
//			
//		
//		return res;
//	}
}
