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.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;


public class Recycle {

	
	public Recycle() {
		
		String line;
		Integer maxInputs,output;
		Integer a, b;
		try {
			BufferedReader read = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("input")));
			BufferedWriter write = new BufferedWriter(new FileWriter("output"));
			maxInputs = new Integer(read.readLine());
			for(int i = 1 ; i <= maxInputs ; i++)
			{
				int success = 0;
				line = read.readLine();
				String[] numbers = line.split(" ");
				a = new Integer(numbers[0]);
				b = new Integer(numbers[1]);
				
				success = getCount(a,b);
				
				output = new Integer(success);
				write.write("Case #"+i+": ");
				write.write(output.toString());
				write.write("\n");
			}
			write.close();
		
		
		}catch (IOException e) {
			
				e.printStackTrace();
			}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		long startTime = System.currentTimeMillis();
		new Recycle();
		long endTime = System.currentTimeMillis();
		System.out.println("Took "+(endTime - startTime) + " ms");
	}

	int getCount(int start, int end)
	{
		
		
		int count = 0 ;
		
		String numStart = new Integer(start).toString();
		int digits = numStart.length();
		String num ;
		char[] perm = new char[digits];
		
		
		
		if(digits == 1)
			return 0;
		
		int[] n = new int[digits];
		boolean set;
		for( Integer i = start; i <= end; i++)
		{
			num = i.toString();
			int mnCount = 0 ;
			for( int j = 1; j < digits; j++)
			{
				for(int k = 0 ; k < digits; k++)
				{
					perm[k] = num.charAt((j+k)%digits); 
				}
				Integer permNum = Integer.parseInt(new String(perm));
				
				if(i < permNum && permNum >= start && permNum <= end)
					{
					set = false;
					for(int temp = 0; temp < mnCount ; temp++)
					{
						if(n[temp] == permNum)
							set = true;
					}
					if(!set)
					{
						count++;
						n[mnCount] = permNum;
						mnCount++;
					}
					}
			}
			
			
			
			
		}
		
		return count;
	}
}
