
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.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

public class RecycledNumbers {

	
	int A;
	int B;
	int count = 0;
	List pairs = new ArrayList<String>();
	
	public static void main(String[] args) {
		
		int T;
		
		BufferedReader bf;
		try {
			bf = new BufferedReader(new FileReader("C-small-attempt1.in"));
			T = Integer.parseInt(bf.readLine().trim());
			
			for (int i = 0; i <= T -1 ; i++) {
				
				RecycledNumbers rn = new RecycledNumbers();
				String[] line = bf.readLine().split(" ");
				rn.A = Integer.parseInt(line[0]);
				rn.B = Integer.parseInt(line[1]);
				rn.count = 0;
				
				rn.resolve();
				
				rn.printOut(i + 1);
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	private void printOut(int i) {
		
		System.out.println("Case #" + i + ": " + count);
	}

	private void resolve() {
		int min = A;
		int minLength;
		if(min < 12){
			min = 12;
		}
		
		while (min <= B){
			String minS = String.valueOf(min); 
			String start = "";
			String end = "";
			minLength = minS.length();
			for (int i = 0; i < minLength -1; i++) {
				start = minS.substring(0,i +1 );
				end = minS.substring(i +1);
				if ( checkNewPair(minS, start,end)){
					count += 1;
				}
			}
			min += 1;
		}
	}

	private boolean checkNewPair(String minS, String start, String end) {
		if (end.charAt(0) == '0'){
			return false;
		}
		
		int newNumber = Integer.parseInt(end + start);
		
		if (newNumber > B ){
			return false;
		}
		
		int min = Integer.parseInt(minS);
		
		String newPair = "";
		if (min < newNumber){
			newPair = minS +"," + newNumber;
		}else if(min > newNumber){
			return false;
		}else if (min == newNumber){
			return false;
		}
			
		if ( pairs.contains(newPair)){
			return false;
		}
		pairs.add(newPair);
		return true;
	}

}


