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.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;


public class Main 
{
	
	public static HashMap<Character,Character> mapp = new HashMap<Character,Character>();
	
	public static void main(String[] args) throws Exception
	{
		PrintWriter writer = new PrintWriter(new FileWriter("output.txt"));
		BufferedReader input = new BufferedReader(new FileReader("C-large.in"));
		int size=Integer.parseInt(input.readLine());
		for(int i=0; i<size; i++)
		{
			Set<String> mySet = new HashSet<String>();
			String tokens[] = input.readLine().split(" ");
			int lowLimit = Integer.parseInt(tokens[0]);
			int highLimit = Integer.parseInt(tokens[1]);
			int count=0;
			for(int j=lowLimit; j<highLimit; j++)
			{
					Integer num1 = j;
					String str1 = num1.toString();
						for(int x=0; x<str1.length(); x++)
						{
							String temp = (String)str1.subSequence(str1.length()-1-x, str1.length()) + (String)str1.subSequence(0, (str1.length()-1-x));
							
							//System.out.println("temp="+temp+"	Str2="+str2);
							if(Integer.parseInt(temp)>j && Integer.parseInt(temp)<=highLimit)
							{
								mySet.add(str1+temp);
							}
						}
			}
			writer.println("Case #"+(i+1)+": "+mySet.size());
		}
		writer.close();
		input.close();
	}

}
