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.*;
import java.util.*;
public class newRecycledNumbers
{
    static HashMap<String,String> map;
    static int[] recycleNumber(int a){
        String s = Integer.toString( a );
        int[] arr = new int[s.length()];
        arr[0] = a;
        for ( int i = 1; i < s.length() ; i++)
            arr[i] = (int)( a/Math.pow( 10, i ) ) + (int)(a%Math.pow( 10, i ))*(int)(Math.pow( 10, s.length()-i ));
        return arr;
    }
    static void solve(int a, int b){
        int[] arr;
        int size = map.size();
        for ( int n = a; n < b; n++){
            arr = recycleNumber(n);
            for ( int j = 0; j < arr.length; j++)
                if ( arr[j] > n && arr[j] <= b)
                    map.put( Integer.toString( n ) + ", " + Integer.toString(arr[j]), "" );
        }
        System.out.println(map.size()-size);
    }
    public static void main (String[] args) throws IOException
    {
        BufferedReader reader = new BufferedReader(new FileReader("recycle.in"));
        int T = Integer.parseInt(reader.readLine()), a,b;
        for ( int i = 0; i < T; i++){
            map = new HashMap<String,String>();
            StringTokenizer st= new StringTokenizer(reader.readLine());
            a = Integer.parseInt( st.nextToken() );
            b = Integer.parseInt( st.nextToken() );
            System.out.print("Case #" + (i+1) + ": ");
            solve(a,b);
        }
    }
}