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.util.*;
import java.io.*;

public class C
{
	public static int roll (int i, int a, int b)
	{
		int found = 0;
		int digits = (""+i).length();
		
		int[] vit = new int[digits];
		
		int magic;
		
		int keep, move,done;
		
		
		for (int d = 1; d < digits; d++)
		{
			magic = (int)Math.pow(10, d);
			keep = i/magic;
			move = i%magic;
			magic = (int)Math.pow(10, digits-d);
			done = keep + (move * magic);
		
			
			if (a <= done && done <= b && done < i)
			{
				vit[found] = done;
				found++;
			}
		}
		
		if (found > 1) 
		{
			Arrays.sort(vit);
			for (int j = 0; j < vit.length - 1; j++)
				if (vit[j] != 0 && vit[j] == vit[j+1])
					found--;
		}
		return found;
	}

	public static void main(String... args) throws Exception
	{
		BufferedReader in = new BufferedReader (new FileReader( "C-large.in" ));
		
		String line;
		in.readLine(); 
		int casenum = 1;

		int a,b;
			
		String[] nums;
		while ( (line = in.readLine()) != null)
		{
			nums = line.split(" ");
			
			a = Integer.valueOf(nums[0]);
			b = Integer.valueOf(nums[1]);
			
			int result = 0;
			for (int m = a; m <= b; m++)
				result += roll(m,a,b);
	
			System.out.println("Case #" + casenum + ": " + (result));
			casenum++;
		}
	}
}