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 static java.util.Arrays.deepToString;

import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class QC {

	public static void main(String[] args) throws Exception 
	{
		new QC().run();
		
	}

	int calculateDigit(int num)
	{
		int res = 0;
		
		while(num>0)
		{
			res++;
			num = num/10;
		}
		
		return res;
	}
	
	void run() throws Exception 
	{
		//Scanner sc = new Scanner(System.in);
		//PrintWriter pw = new PrintWriter(System.out);
		
		Scanner sc = new Scanner(new FileReader("C-large.in"));
		
		FileWriter fstream = new FileWriter("out.in");
		BufferedWriter out = new BufferedWriter(fstream);

		int ntest = Integer.valueOf(sc.nextLine());
		
		
		
		for(int test=1;test<=ntest;++test) 
		{
			int min = sc.nextInt();
			int max = sc.nextInt();
			int score = 0;

			for(int i=min; i<=max; i++)
			{
				int digit = calculateDigit(i);
				List<Integer> list = new ArrayList<Integer>();
				for(int j=1; j<digit; j++)
				{
					
					int head = (int) (i/(Math.pow(10, j)));
					int tail = (int) (i%(Math.pow(10, j)));
					
					int mix = (int) (tail*Math.pow(10,(digit-j)) + head);
					//debug(i+ " " +head+" "+tail);
					if(list.indexOf(mix) == -1 && mix <= max && mix > i && calculateDigit(mix) == calculateDigit(i))
					{
						//debug(i + " " +mix);
						list.add(mix);
						score++;
					}
				}
				
			}
		
			out.write("Case #" + test + ": ");
			out.write(score+"");
			debug(score);
			out.write("\n");
		}
		out.close();
		sc.close();
	
	}
	
	void debug(Object...os) 
	{
		System.err.println(deepToString(os));
	} 
	
	void debugArray(Object[]...os) 
	{
		System.err.println(deepToString(os));
	} 
}
