import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: aeg
 * Date: 12/04/14
 * Time: 22:58
 * To change this template use File | Settings | File Templates.
 */
public class ReceycledNumbers {
    public static void main (String[] argc) throws FileNotFoundException {
        ReceycledNumbers  renum = new ReceycledNumbers();
        renum.solve();

    }

    private void solve() throws FileNotFoundException {
        FileInputStream fis = new FileInputStream("csv/QR_C/C-large.in");
        Scanner sc = new Scanner(fis);

        int T = sc.nextInt();

        loop:
        for (int i = 0; i < T; i++) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            int count =0;

            System.out.print("Case #"+(i+1)+": ");
            if (B < 10) {
                System.out.println("0");
                continue;
            }
            for (int j = A; j < B; j++) {
                String str = ((Integer) j).toString();
                count +=tryRecycle(str, j, B);

            }
            System.out.println(count);
        }
      }

    private int tryRecycle(String str, int j, int b) {
        int count=0;
        for(int i=1;i<str.length();i++){
            String s2 = str.substring(str.length()-i,str.length()) + str.substring(0,str.length()-i);
            Integer i2 = Integer.valueOf(s2);
            if ((j < i2) && (i2 <= b)) {
                count++;
            }
        }
        return count;
    }


}
