package codejam;

import java.util.*;
import java.io.*;

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}

import java.io.*;
import java.util.*;

public class Q3
{
	public static boolean isPermut (int a, int b)
	{
		String str = String.valueOf (a);
		for (int i = 1; i < str.length(); i++)
		{
			str = str.charAt (str.length() - 1) + str.substring (0, str.length() - 1);
			if (Integer.parseInt (str) == b)
			{
				return true;
			}
		}
		return false;
	}
	
	public static void main (String[] args) throws IOException
	{
		BufferedReader reader = new BufferedReader (new FileReader ("input-q3.txt"));
		PrintWriter writer = new PrintWriter ("output-q3.txt");
		String line = reader.readLine();
		int nb = Integer.parseInt (line);
		for (int i = 0; i < nb; i++)
		{
			line = reader.readLine();
			String[] tokens = line.split (" ");
			int min = Integer.parseInt (tokens[0]);
			int max = Integer.parseInt (tokens[1]);
			
//			System.out.printf ("\nmin %d, max %d\n", min, max);
			
			// Try all rotations
			int counter = 0;
			
			Set<Integer> set = new HashSet<Integer>();
			
			for (int val = min; val < max; val++)
			{
				String str = String.valueOf (val);
				int nbDigits = str.length();
//				System.out.println("Val : " + val + " with " + nbDigits + " digits");
				int major = String.valueOf (max).charAt (0) - '0';
				set.clear();
				
				for (int j = 1; j < nbDigits; j++)
				{
					char last = str.charAt (nbDigits - 1);
					str = str.charAt (nbDigits - 1) + str.substring (0, nbDigits - 1);
					if (last != '0' && (last - '0') <= major)
					{
//						System.out.println ("  Trying " + str);
						int res = Integer.valueOf (str);
						if (res <= max && res > val && ! set.contains (res))
						{
//							System.out.printf ("    (%d, %d)\n", val, res);
							set.add (res);
							if (! (val != res && val < res && val >= min && res <= max && isPermut (res, val)))
							{
								System.out.println("ERROR");
							}
							counter++;
						}
					}
				}
			}
//			System.out.println ("Counter : " + counter);
			writer.println ("Case #" + (i + 1) + ": " + counter);
		}
		writer.close();
		reader.close();
	}
}