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.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class RecycledNumbers {
	public static void main(String[] args) {
		int cases = 0, a = 0, b = 0, answer = 0;

		String in = "C-large";
		
		try {
			BufferedReader br = readFile(new FileReader(in + ".in"));
			FileWriter fstream = new FileWriter(in + ".out");
			BufferedWriter out = new BufferedWriter(fstream);
			
			String inline;
			int i = 0;
			while ((inline = br.readLine()) != null) {
				if (i++ == 0) {
					cases = Integer.parseInt(inline);
				} else {
					String result = "Case #" + (i - 1) + ": ";
					String[] input = inline.trim().split(" ", 2);
					answer = 0;
						
					a = Integer.parseInt(input[0].trim());
					b = Integer.parseInt(input[1].trim());
					
					if (b > 10) {
						int sub = 0;
						Map<String, Object> map = new HashMap<String, Object>();
						for (int n=a; n<=b; n++) {
							if (n < 10) {n = 10; continue;}
							
							String sn	= String.valueOf(n);
							sub			= sn.length();
							int m		= 0;
							
							for (int o=0; o<sub-1; o++) {
								String m1 = sn.substring((sub-1) - o);
								String m2 = sn.substring(0, (sub-1) - o);
								
								m = Integer.parseInt(m1 + m2);
								
								if (m > n 
										&& m <= b
										&& !map.containsKey(n + "," + m)) {
									//System.out.println(n + "," + m);
									map.put(n + "," + m, n + "," + m);
									answer++;
								}
								
							}
						}
					}
					
					writeOutput(result + answer, out);
				}
			}
			out.close();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	private static BufferedReader readFile(FileReader in) throws FileNotFoundException {
		return new BufferedReader(in);
	}
	
	private static void writeOutput(String text, BufferedWriter out) throws IOException {
		out.write(text);
		out.write("\n");
	}
}
