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.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Recycle2 {
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(new BufferedReader(new FileReader("/Users/sunny/Desktop/C-large.in")));
		PrintWriter out=new PrintWriter(new FileWriter("/Users/sunny/Desktop/C-large.out"));
		int n = in.nextInt(); String i1, i2, line ; 
		for( int i = 1 ; i <= n ; i++){
			i1 = in.next() ; i2 = in.next() ;  
			line = "Case #"+i+": "+findN(i1, i2);
			System.out.println(line);
			out.println(line);
		}
		out.close() ;
	}
	
	private static int findN(String i1, String i2) {
		Integer n = new Integer(i1), m = new Integer(i2);
		int count = 0 ; String xx ;
		for(int x = n ; x <= m ; x++) {
			xx = ""+x; int length = xx.length() ; 
			Set<String> pairs = new HashSet<String>(xx.length());
			int j ;
			for(int i=1 ; i < length ; i++ ) {
				j = Integer.parseInt(xx.substring(i)+xx.substring(0,i)); 
				if(j <= m && j >=n && j !=x ) {
					if(!pairs.contains(x+"-"+j)) {
						pairs.add(x +"-"+j);
						count++;
					}
				}
			}
		}
		return count/2;
	}
}
