import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

public class Recycled {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int t = Integer.parseInt(br.readLine());
            for (int i = 0; i < t; i++) {
                String[] str = br.readLine().split(" ");
                int a = Integer.parseInt(str[0]);
                int b = Integer.parseInt(str[1]);
                System.out.println("Case #" + (i + 1) + ": " + find(a, b));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static int find(int a, int b) {
        HashSet<Long> used = new HashSet<Long>();
        int digits = String.valueOf(a).length();
        if (digits == 1) return 0;
        for (int i = a; i <= b; i++) {
            int s = 10;
            int m = (int) Math.pow(10, digits-1);
            for (int j = 0; j < digits-1; j++) {
                int r = i % s;
                if (r < s/10) continue;
                int q = i / s;
                int rn = r * m + q;
                s *= 10; m /= 10;
                if (i != rn && rn >= a && rn <= b) {
                    long pp;
                    if (rn < i) pp = (long)rn << 30 | i;
                    else pp = (long)i << 30 | rn;
                    if (!used.contains(pp)) {
                        used.add(pp);
                    }
                }
            }
        }
        return used.size();
    }
}

import java.io.*;

public class RecycledNumbers {


	public static void main(String[] args) {

		BufferedReader in;
		BufferedWriter out;
		int T, i;
		String line;
		

		try {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new BufferedWriter(new FileWriter("output.txt"));
		} catch (FileNotFoundException e) {
			System.out.println(e.getMessage());
			return;
		} catch (IOException e) {
			System.out.println(e.getMessage());
			return;
		}

		try {
			T = Integer.parseInt(in.readLine());

			for (i = 0; i < T; i++) {
				line = in.readLine();

				String lineToWrite = "Case #" + (i+1) + ": ";

				lineToWrite += String.valueOf(solve(line));

				out.write(lineToWrite + "\n");

			}
			in.close();
			out.close();
		} catch (IOException e) {
			System.out.println(e.getMessage());
			return;
		}
	}

	public static int solve(String input) {
		int a, b, counter;
		String[] inputs = input.split(" ");
		a = Integer.parseInt(inputs[0]);
		b = Integer.parseInt(inputs[1]);
		counter = 0;

		for (int n = a; n < b; n++) {

			int i;
			for (i = 10; i < b; i *= 10) {
				int m = split(n, i);

				if (m > n && m <= b) counter++;

			}


		}
		return counter;

	}
	
	public static int split(int num, int pow) {
		int half1, half2;
		half1 = num/pow;
		half2 = (num%pow) * (orderOf(num) / pow);
		return half1 + half2;
	}
	
	public static int orderOf(int num) {
		int i = 1;
		while (i < num) {
			i*=10;
		}
		return i;
	}
}
