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.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;


public class Recycle {

	/**
	 * @param args
	 */
	
	static int t =0;
	
	//static ArrayList<ArrayList<String>> table = new ArrayList<ArrayList<String>>();	

		public static void inputF() throws FileNotFoundException{
			
			File inputFile = new File("C-large.in");
			Scanner in = new Scanner(inputFile);
			File outputFile = new File("C-large.out");
			PrintWriter out = new PrintWriter(outputFile);
			String result="";
			String input ="";
	  
			int n,m=0;
			
			t = in.nextInt();
			//System.out.println(n);
			input = in.nextLine();
			for (int i=1; i<=t; i++) {
				 n =in.nextInt();
				 m =in.nextInt();
				//System.out.println("length of the list: "+list.length);
				result = "Case #"+i+ ": "+ count(n,m);
				out.println(result);
			}
			in.close();
			out.close();
		}
	
	private static int count(int n, int m) {
		int result =0;	
		boolean isRecycle = false;
		ArrayList list = new ArrayList<Integer>();
		
		for (int i=n; i<=m;i++){
			String ori=Integer.toString(i);
			isRecycle = false;
			list = new ArrayList<Integer>();
			for(int j=1; j<ori.length();j++){
				String cut = ori.substring(j, ori.length());
				String res = (cut+ori).substring(0, ori.length());
				//System.out.println(res);
				int resInt = Integer.parseInt(res);
				if ((resInt>i)&(resInt<=m)) {
					if ((!isRecycle)|((isRecycle)& (!list.contains(resInt)))){
					result++;
					isRecycle=true;
					list.add(resInt);
					//System.out.println(i+"-->"+resInt);
					//out.println(resInt);
				}
				}
			}
		}
		return result;
		}

	public static void main(String[] args) throws FileNotFoundException {
		inputF();

	}

}
