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

import java.io.*;
import java.lang.Math.*;
import java.util.Arrays;

public class C {

	public static void main(String[] args) {

		try {
			BufferedReader input = new BufferedReader(new FileReader("C:/CodeJam/C-large.in"));
			BufferedWriter output = new BufferedWriter(new FileWriter("C:/CodeJam/C-large.out"));
			try {
				int T = Integer.parseInt(input.readLine());

				//Process each case
				for (int i = 0; i < T; i++) {
					String line = input.readLine();
					String[] AB = line.split(" ");
					int A = Integer.parseInt(AB[0]);
					int B = Integer.parseInt(AB[1]);
					String max = String.valueOf(B);

					//Check every n,m pair for cur case
					int count = 0;
					for (int j = A; j < B; j++) {
						String n = String.valueOf(j);
						String m = n;
						int len = m.length();
						//For single digit numbers, no matches possible
						if (len == 1) {
							break;
						}
						//Check each possible match for current n
						int[] matches = new int[len];
						int subcount = 0;
						for (int k = 0; k < len; k++) {
							//Check current permutation of m for valid range
							if (m.compareTo(n) > 0 && m.compareTo(max) <= 0) {
								matches[subcount] = Integer.parseInt(m);
								subcount++;
							}
							//Move the last digit to the front
							m = m.substring(len - 1, len) + m.substring(0, len - 1);
						}
						//Check the matches for duplicates and uncount them
						Arrays.sort(matches);
						for (int k = 0; k < len - 1; k++) {
							if(matches[k] != 0 && matches[k+1] != 0 && matches[k] == matches[k+1]) {
								subcount--;
							}
						}
						count += subcount;
					}

					System.out.println("Case #" + (i + 1) + ": " + count);
					output.write("Case #" + (i + 1) + ": " + count + "\n");
				}
			} finally {
				input.close();
				output.close();
			}
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}
}
