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.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


public class RecycledNumbers {

	static final String input_path = "data/input.c.txt";
	
	private static Set<String> ans = new HashSet<String>();
	
	private static Integer[] getBits(int n) {
		List<Integer> lst = new ArrayList<Integer>();
		while (n != 0) {
			lst.add(n % 10);
			n /= 10;
		}
		
		Integer ans[] = new Integer[lst.size()];
		return lst.toArray(ans);
	}
	
	private static int getInteger(Integer[] bits) {
		int ans = 0;
		int power = 1;
		
		for (int i = 0; i < bits.length; i ++) {
			ans += power * bits[i];
			power *= 10;
		}
		
		return ans;
	}
	
	private static int judge(int n, int b) {
		Integer[] bits = getBits(n);
		if (bits.length == 1)
			return 0;
		int ret = 0;
		
		int len = bits.length;
		for (int pos = 0; pos < len - 1; pos ++) {
			if (bits[pos] == 0)
				continue;
			int new_bits_len = 0;
			Integer[] new_bits = new Integer[len];
			for (int i = pos + 1; i < len; i++) 
				new_bits[new_bits_len ++] = bits[i];
			for (int i = 0; i <= pos; i++) 
				new_bits[new_bits_len ++] = bits[i];
			int new_int = getInteger(new_bits);
			if (new_int <= b && new_int > n) {
				String ans_str = String.format("%d_%d", n, new_int);
				if (!ans.contains(ans_str))
					ans.add(ans_str);
				ret += 1;
			}
				
		}
		return ret;
	}
	
	private static int solve(int a, int b) {
		if (a == b)
			return 0;
		for (int i = a; i < b; i ++) {
			int tmp = judge(i, b);
		}
		return ans.size();
	}
	
	/**
	 * Good luck, Wash!
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader(input_path)); 
		String intext = in.readLine();
		int T = Integer.parseInt(intext);
		for (int caseIter = 0; caseIter < T; caseIter ++) {
			intext = in.readLine();
			System.out.print(String.format("Case #%d: ", caseIter + 1));
			
			String[] parts = intext.split(" ");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			System.out.println(solve(A, B));
			ans.clear();
		}
		in.close();
	}
}
