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.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;


public class RecycledNumbersC {

	static int[] matches;
	static int A, B;
	
	public static void main(String[] args) {
//		Scanner sc = new Scanner(System.in);
		Scanner sc;
		try {
			sc = new Scanner(new FileInputStream("C-large.in"));
		} catch (FileNotFoundException e) {
			sc = new Scanner(System.in); // file not exist, so get input from console
		}
		
		Writer out;
		try {
			out = new OutputStreamWriter(new FileOutputStream("C-large.out"));
		} catch (FileNotFoundException e) {
			out = new OutputStreamWriter(System.out); // use console
		}
		
		int T = sc.nextInt();

		for (int t = 0; t < T; t++) {
			A = sc.nextInt();
			B = sc.nextInt();
			int count = 0;
			
			matches = new int[B];

			for (int i = B; i > A; i--)
				findMatches(i, A);
//				count += findMatches(i, A);
			
			count = countMatches();

			// output
			System.out.println("Case #" + (t + 1) + ": " + count);
			try {
				out.write("Case #" + (t + 1) + ": " + count + "\n");
			} catch (IOException e) {
				// do nothing
			}
		}

		try {
			out.close();
		} catch (IOException e) {
			// do nothing
		}
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	static void findMatches(Integer input, int min) {
		String number = input.toString();
		ArrayList<Integer> checkNums = new ArrayList<Integer>();
		
		for (int i = 1; i < number.length(); i++) {
			number = digitShift(number);
			Integer nextInt = Integer.parseInt(number);
			if (!checkNums.contains(nextInt))
				checkNums.add(nextInt);
		}
		
		Comparator desc = Collections.reverseOrder();
		Collections.sort(checkNums, desc);
		
		for (Integer n : checkNums) {
			if (n < input && n >= min) {
				matches[n]++;
			}
		}
	}
	
	static int countMatches() {
		int count = 0;
		for (int i = 0; i < B; i++)
			count += matches[i];
		return count;
	}

	static String digitShift(String input) {
		return input.substring(1).concat(input.substring(0, 1));
	}

}
