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.Qualification;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;

public class ProblemC {

	private static final String DIRECTORIO = "D:\\CodeJam\\CodeJam2012\\Qualification\\ProblemC\\";

	private static final String FILE_IN = "ejemplo.in";
	// private static final String FILE_IN = "A-small-practice.in";
	// private static final String FILE_IN = "A-small-attempt0.in";
	// private static final String FILE_IN = "A-large.in";

	private static final String FILE_OUT = "ejemplo.out";

	// private static final String FILE_OUT = "a-small-practice.out";
	// private static final String FILE_OUT = "a-small.out";
	// private static final String FILE_OUT = "a-large.out";

	public static void main(String[] args) throws Exception {

		// Se prepara para leer del fichero y escribir
		FileReader fr = new FileReader(DIRECTORIO + FILE_IN);
		BufferedReader bf = new BufferedReader(fr);
		File ficheroOut = new File(DIRECTORIO + FILE_OUT);
		ficheroOut.delete();
		BufferedWriter bw = new BufferedWriter(new FileWriter(ficheroOut));

		int casosPrueba = Integer.parseInt(bf.readLine());

		// Se hace cada caso de prueba
		for (int index = 1; index <= casosPrueba; index++) {
			
			String[] entrada = bf.readLine().split(" ");
			long A = Integer.parseInt(entrada[0]);
			long B = Integer.parseInt(entrada[1]);
			
			
			int parejasEncontradas = 0;
			for (long i=A; i<=B; i++){
				
			
				long digitos = (long) Math.ceil(Math.log10(B));

				ArrayList<Long> listaFijos = new ArrayList<Long>();

				for (int j = 1; j < digitos; j++) {
					long maximo = (long) Math.pow(10, j);
					long candidato = (long) Math.floor((i / maximo));
					candidato = (long) (candidato + (i % maximo)
							* Math.pow(10, digitos - j));

	

					
					
					if (candidato <= B && candidato > i	&& !listaFijos.contains(candidato)) {
						listaFijos.add(candidato);
						parejasEncontradas++;
					}

				}

				
				
			}


			
			
			
			
			

			// Se escribe la solución del caso en pantalla y en fichero
			String solucion = "Case #" + index + ": " + parejasEncontradas;
			bw.write(solucion);
			bw.newLine();
			System.out.println(solucion);
		}

		// Se cierra el buffer de escritura
		bw.close();
	}
}
