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 com.renoux.gael.codejam.fwk;

import java.io.File;

import com.renoux.gael.codejam.utils.FluxUtils;
import com.renoux.gael.codejam.utils.Input;
import com.renoux.gael.codejam.utils.Output;
import com.renoux.gael.codejam.utils.Timer;

public abstract class Solver {

	public void run() {
		Timer.start();
		if (!disableSample())
			runOnce(getSampleInput(), getSampleOutput());
		System.out.println(Timer.check());

		Timer.start();
		if (!disableSmall())
			runOnce(getSmallInput(), getSmallOutput());
		System.out.println(Timer.check());

		Timer.start();
		if (!disableLarge())
			runOnce(getLargeInput(), getLargeOutput());
		System.out.println(Timer.check());

	}

	public void runOnce(String pathIn, String pathOut) {
		Input in = null;
		Output out = null;
		try {

			in = Input.open(getFile(pathIn));
			out = Output.open(getFile(pathOut));

			int countCases = Integer.parseInt(in.readLine());
			for (int k = 1; k <= countCases; k++) {
				out.write("Case #", k, ": ");
				solveCase(in, out);
			}
		} catch (RuntimeException e) {
			e.printStackTrace();
		} finally {
			FluxUtils.closeCloseables(in, out);
		}
	}

	private File getFile(String path) {
		return new File(path);
	}

	protected abstract void solveCase(Input in, Output out);

	private String getFullPath(boolean input, String type) {
		if (input)
			return "D:\\Downloads\\CodeJam\\" + getProblemName() + "\\"
					+ getProblemName() + "_input_" + type + ".txt";
		else
			return "D:\\Downloads\\CodeJam\\" + getProblemName() + "\\"
					+ getProblemName() + "_output_" + type + ".txt";
	}

	protected String getSampleInput() {
		return getFullPath(true, "sample");
	}

	protected String getSmallInput() {
		return getFullPath(true, "small");
	}

	protected String getLargeInput() {
		return getFullPath(true, "large");
	}

	protected String getSampleOutput() {
		return getFullPath(false, "sample");
	}

	protected String getSmallOutput() {
		return getFullPath(false, "small");
	}

	protected String getLargeOutput() {
		return getFullPath(false, "large");
	}

	protected boolean disableSample() {
		return disable()[0];
	}

	protected boolean disableSmall() {
		return disable()[1];
	}

	protected boolean disableLarge() {
		return disable()[2];
	}

	protected boolean[] disable() {
		return new boolean[] { false, false, false };
	}

	protected abstract String getProblemName();
}
