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

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}

package codejam2012;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class QualC {
	public static void main(String[] args) throws FileNotFoundException {
		Scanner in = new Scanner(new FileInputStream(new File("/home/rush/sample-in.txt")));
		PrintWriter out = new PrintWriter(new FileOutputStream("/home/rush/sample-out.txt"));
		
//		Scanner in = new Scanner(System.in);
//		PrintWriter out = new PrintWriter(System.out);
		int t = in.nextInt();
		
		
		Map<Integer, Integer> count = new HashMap<Integer, Integer>();
		for (int i = 0; i < t; i++) {
			int total = 0;
			
			int s = in.nextInt();
			int e = in.nextInt();
			
			for (int j = s; j <= e; j++) {
				if (count.containsKey(j)) {
					total += count.get(j);
					continue;
				}
				
				String num = j + "";
				int cnt = 0;
				Map<Integer, Boolean> map = new HashMap<Integer, Boolean>();
				for (int k = 1; k < num.length(); k++) {
					String pre = num.substring(0, k);
					String post = num.substring(k);
					String tnum = post + pre;
					int tn = Integer.parseInt(tnum);
					if (j < tn && tn <= e && !map.containsKey(tn)) {
						cnt++;
						total++;
						map.put(tn, true);
					}
				}
				count.put(j, cnt);
			}
			
			out.printf("Case #%d: %d", (i+1), total);
			out.println();
		}
		out.flush();
	}
}
