
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.io.BufferedWriter;

public class Recycle
{
	public static void main(String[] args)
	{
/*		Set<Integer> perms = getPermutations(123456);
		
		for(Integer i: perms)
			System.out.println(i);*/
	
		try
		{
			Scanner s = new Scanner(new File("recycle.in"));
			BufferedWriter w = new BufferedWriter(new FileWriter(new File("recycle.out")));
			int numCases = s.nextInt();
			s.nextLine();
			
			for(int n = 1;n <= numCases; n++)
			{
				int A = s.nextInt();
				int B = s.nextInt();
				int count = 0;
				for(int k = A; k <= B; k++)
				{
					count += getNumPairs(k, B);
				}
				
				w.write("Case #" + n + ": " + count + "\n");
			}
			
			w.flush();
			w.close();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public static int getNumPairs(int n, int B)
	{
		Set<Integer> possibles = getPermutations(n);
		int count = 0;
		for(Integer i : possibles)
			if(i > n && i <= B)
				count++;
		return count;
	}
	
	public static Set<Integer> getPermutations(int n)
	{
		Set<Integer> perms = new TreeSet<Integer>();
		char[] digits = String.valueOf(n).toCharArray();
		
		for(int firstPos = 1; firstPos < digits.length; firstPos++)
		{
			String toBuild = "";
			for(int k = 0; k < digits.length; k++)
				toBuild += digits[(firstPos + k) % digits.length];
			perms.add(Integer.parseInt(toBuild));
		}
		return perms;
	}
	

}

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;


public class Recycled_Numbers {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {

			Scanner sc = new Scanner(new File("C-small-attempt0.in"));
			int caseNo = sc.nextInt();
			FileWriter fstream = new FileWriter("C-small-attempt0.out");
			BufferedWriter out = new BufferedWriter(fstream);

			for(int i = 1; i <= caseNo; i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				int recyclableNo = 0;
				int start;
				int end;

				if(a > b) {
					end = a;
					start = b;
				} else {
					end = b;
					start = a;
				}
				System.out.println("test");
				for(int j = start; j <= end; j++) {
					for(int k = end; k > j; k--) {
						if(isPermutation(j, k)) {
							if(isEquivalent(j, k)) {
								recyclableNo++;
							}
						}
					}
				}

				System.out.println("Case #" + i + ": " + recyclableNo);



				out.write("Case #" + i + ": " + recyclableNo);
				out.newLine();

			}

			//Close the output stream
			out.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private static int getNoOfDigits(long num) {
		int digitCount = 0;
		while(num > 0) {
			num /= 10;
			digitCount++;
		}
		return digitCount;
	}

	private static boolean isPermutation(int num1, int num2) {
		boolean result = false;
		int[] arr = new int[10];

		int temp = num2;
		while (temp > 0) {
			arr[temp % 10]++;
			temp /= 10;
		}

		temp = num1;
		while (temp > 0) {
			arr[temp % 10]--;
			temp /= 10;
		}


		for (int i = 0; i < 10; i++) {
			if (arr[i] != 0) {
				result = true;                
			}
		}

		return !result;
	}

	private static boolean isValidPermutation(int num1, int num2) {
		boolean result = false;
		int noOfMatches = 0;
		int currentPointToBegin = -1;
		int temp = num2 % 10;

		int[] arr1 = getDigitsInArray(num1);

		for(int i = 0; i < arr1.length; i++) {
			if(arr1[i] == temp) {
				noOfMatches++;
				if(currentPointToBegin == -1) {
					currentPointToBegin = i;
				}
			}
		}

		int temp2 = num2;

		while(temp2 > 0) {
			if(noOfMatches > 0) {
				noOfMatches--;
				for(int i = 0; i < arr1.length; i++) {
					
				}
			}
		}

		return result;
	}

	private static int[] getDigitsInArray(int num) {
		int i = getNoOfDigits(num);
		int[] arr = new int[i];
		while(num > 0) {
			arr[i - 1] = num % 10;
			num /= 10;
			i--;
		}
		return arr;
	}

	private static boolean isEquivalent(int num1, int num2) {
		boolean result = false;
		int rem;
		int digitNo = getNoOfDigits(num1);
		for(int i = 0; i < digitNo; i++) {
			if(num1 == num2) { 
				result = true;
				break;
			}
			rem = num1 % 10;
			num1 /= 10;
			num1 += rem * Math.pow(10, digitNo - 1);
		}
		return result;
	}
}
