
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;
	}
	

}
package recycling;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	
	public static int lint(int n){
		if(n == 0)
			return 0;
		return 1 + lint(n / 10);
	}
	
	public static void permut(int[] tab){
		int l = tab.length;
		int temp = tab[l - 1];
		for(int i = l - 1; i > 0; i--){
			tab[i] = tab[i - 1];
		}
		tab[0] = temp;
	}
	
	public static int toInt(int[] tab){
		int res = 0;
		int m = 1;
		for(int i = tab.length - 1; i >= 0; i--){
			res += m * tab[i];
			m *= 10;
		}
		return res;
	}
	
	public static int[] toTab(int n){
		int[] res = new int[lint(n)];
		int temp = n;
		for(int i = res.length - 1; i >= 0; i--){
			res[i] = temp % 10;
			temp /= 10;
		}
		return res;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//String fileName = args[0];
		String fileName = "recycling/C-small-attempt0.in";
		Scanner sC = null;
		try {
			sC = new Scanner(new File(fileName));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		int T = sC.nextInt();
		int A, B, l;
		
		for(int i = 0; i < T; i++){
			A = sC.nextInt();
			B = sC.nextInt();
			
			l = lint(A);
			
			int[] tab;
			
			int temp;
			
			int count = 0;
			
			for(int j = A; j < B; j++){
				tab = toTab(j);
				for(int k = 0; k < l - 1; k++){
					permut(tab);
					temp = toInt(tab);
					//System.out.println(j + " " + temp);
					if(temp > j && temp <= B){
						count++;
						//System.out.println(j + " " + temp);
					}
				}
			}
			
			System.out.println("Case #" + (i + 1) + ": " + count);
		}

	}

}
