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

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.ArrayList;

public class TestCaseIO {

    public static ArrayList<TestCase> loadFromFile(String infile) {
        //inc checks on #lines, length of splits, etc.
        BufferedReader br = Utils.newBufferedReader(infile);
        ArrayList<TestCase> tcList = new ArrayList<>();

        //first line is N, the number of test cases
        Integer N = Utils.readInteger(br);

        //cycle through N test cases
        for (int x = 0; x < N; x++) {
            TestCase tc = new TestCase();
            tc.setRef(x + 1);

            ///////////////////////////////////////////////////////////
            //load properties - the bit to customise per problem
            ArrayList<Integer> l = Utils.readIntegerList(br, 2);
            tc.setIntegerList("a_b", l);

            ///////////////////////////////////////////////////////////

            tcList.add(tc);
        }

        //confirm end of file
        if (Utils.readLn(br) != null) {
            Utils.die("Unexpected text at end of infile");
        }

        return tcList;
    }

    public static ArrayList<TestCase> mockUp() {

        ArrayList<TestCase> tcList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            TestCase tc = new TestCase();
            tc.setRef(i);
            
            int[] xs = Utils.randomIntegerArray(100, -50, 50, i * 2);
            int[] ys = Utils.randomIntegerArray(100, -50, 50, i * 2 + 1);
            tc.setIntegerList("xs", Utils.arrayToArrayList(xs));
            tc.setIntegerList("ys", Utils.arrayToArrayList(ys));

            tcList.add(tc);
        }
        return tcList;
    }

    public static void writeSolutions(ArrayList<TestCase> tcList, String outfile) {

        BufferedWriter bw = Utils.newBufferedWriter(outfile, false);

        for (int i = 0; i < tcList.size(); i++) {
            TestCase tc = tcList.get(i);
            Object solution = tc.getSolution();
            String line = "Case #" + (i + 1) + ": " + solution.toString();
            Utils.writeLn(bw, line);
        }

        Utils.closeBw(bw);

    }
}
