
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.File;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


public class CodejamC {

	public static final String TEST = "test.in", SMALL = "C-small-attempt0.in", LARGE = "C-large.in";
	public static final String OUTPUT = "out.txt";
	
	static int count = 0;
	
	public static void main(String[] args) throws Exception
	{
		
		solve(SMALL);
	}

	public static void solve(String filename) throws Exception
	{
		Scanner in = new Scanner(new File(filename));
		
		int cases = in.nextInt();
		in.nextLine();
		
		PrintWriter out = new PrintWriter(new File(OUTPUT));
		
		for(int num = 1; num <= cases; num++)
		{
			int a = in.nextInt();
			int b = in.nextInt();
			count = 0;
			in.nextLine();
			int result = 0;
			Set<Pair> perms = new HashSet<Pair>();
			for(int i = a; i <= b; i++)
			{
				String str = String.valueOf(i);
				for(int j = 0; j < str.length(); j++)
				{
					String newStr = str.substring(str.length() - j, str.length()) + str.substring(0, str.length() - j);
					int val = Integer.parseInt(newStr);
					if(val >= a && val <= b && !newStr.equals(str) && newStr.charAt(0)!='0')
					{
						perms.add(new Pair(str, newStr));
					}
				}
				//perms.remove(str);
			}
			result = perms.size();
			out.println("Case #"+num+": "+result);
			System.out.println("Case #"+num+": "+result);
		}
		
		out.close();
	}
}

class Pair
{
	String n, m;
	
	public Pair(String str, String newStr) {
		n = str;
		m = newStr;
	}

	@Override
	public boolean equals(Object o)
	{
		Pair other = (Pair) o;
		return (n.equals(other.n)&& m.equals(other.m)) || (m.equals(other.n) && n.equals(other.m));
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return n.hashCode() + m.hashCode();
	}
	
	
}
