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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 *
 * @author Anirban
 */
public class RecycledNumbersLarge {
    static int MAXN = 2000000;
    static int arr[] = new int[MAXN + 1];

    public static boolean check(String n, String m, int len){
        for(int i = 0; i < len; i++){
            if(m.compareTo(n.substring(i, i + len)) == 0)
                return true;
        }
        return false;
    }

    public static void main(String [] args)throws IOException{
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);

        int tc = 1;

        //int T = 50;
        int T = Integer.parseInt(br.readLine());
        while(T-- > 0){

            int count = 0;
            StringTokenizer st = new StringTokenizer(br.readLine(), " ");
            int A = Integer.parseInt(st.nextToken());
            int B = Integer.parseInt(st.nextToken());

            //int A = 1;
            //int B = 2000000;
            ArrayList <Integer> L = new ArrayList<Integer>();

            String b = B + "";
            for(int i = A; i <= B; i++){
                String n = i + "";
                String x = n;
                int len = n.length();
                n += n;
                L.clear();
                for(int j = 0; j < len; j++){
                    String m = n.substring(j, j + len);
                    int mm = Integer.parseInt(m);
                    if(!L.contains(mm)){
                        m = mm + "";
                        if(i < mm && x.length() == m.length() && B >= mm){
                            count++;
                            //System.out.println(n.substring(0, len) + " " + m);
                        }
                        L.add(mm);
                    }
                }
            }
            System.out.printf("Case #%d: %d", tc, count);
            System.out.println();
            tc++;
        }
    }
}
