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();
		}
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Writer;
import java.util.Arrays;

/**
 * Recycled Numbers
 * @author shibink
 *
 */
public class Recycle {

    public static int getCount(String str) {
        int count = 0;
        long tmp = 0;
        int numDigits = 0;

        if ((str == null) || (str.isEmpty())) {
            return count;
        }

        String[] strArray = str.split(" ");
        
        // It should be 2
        if (strArray.length != 2) {
            return 0;
        }
        long num1 = Long.parseLong(strArray[0]);
        long num2 = Long.parseLong(strArray[1]);
        tmp = num1;

        // Find number of digits in num1 & num2
        while (tmp > 0) {
            numDigits++;
            tmp = tmp / 10;
        }
        
        long arr[] = new long[numDigits];
        int cnt;
        for (long i = num1; i <= num2; i++) {
            Arrays.fill(arr, 0);
            cnt = 0;
            for (long val = i, j = 1; j < numDigits; j++) {
                tmp = val % 10;

                if (tmp == 0) {
                    val = val/10;
                    continue;
                }
                val = (int) (tmp * Math.pow(10, (numDigits - 1)) + (val / 10));
                for (int k=0; k<cnt; k++) {
                    if (val == arr[cnt]) {
                        continue;
                    }
                }
                arr[cnt++] = tmp;
                if ((val > i) && (val <= num2)) {
                    count++;
                }
            }
        }
        return count;
    }

    public static void processFile(String fileName) throws IOException {
        FileInputStream fstream = new FileInputStream(fileName);
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));

        // use buffering
        Writer output = new BufferedWriter(new FileWriter("output.txt"));

        try {
            String strLine = null;
            int numRecycle = 0;
            int count = 0;

            if ((strLine = br.readLine()) != null) {
                count = Integer.parseInt(strLine);
            }
            // Read File Line By Line
            for (int i = 1; i <= count; i++) {
                if ((strLine = br.readLine()) == null) {
                    return;
                }

                numRecycle = getCount(strLine);
                System.out.println("Case #" + i + ": " + numRecycle);

                StringBuffer outBuff = new StringBuffer("Case #" + i + ": " + numRecycle + "\n");
                output.write(outBuff.toString());
            }

        } finally {
            // Close the input stream
            in.close();
            output.close();
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        String fileName = "input.in";
        try {
            processFile(fileName);
        } catch (IOException e) {
            // TODO Log error
        }
        return;
    }
}
