package codejam;

import java.util.*;
import java.io.*;

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}


import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Eunice
 */
public class Recycled_Numbers {

    static Scanner scanner = new Scanner(System.in);
    static PrintWriter out;

    public static void main(String[] args) {

        try {
             out = new PrintWriter(new FileWriter("C:\\Users\\Eunice\\Desktop\\Code Jam\\CodeJam Outputs\\Recycled_Numbers.txt" ));
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }

        int noTestCases = scanner.nextInt();
        for(int i = 0; i < noTestCases; i++) {
            int A = scanner.nextInt();
            int B = scanner.nextInt();
            int noRecycledPairs = 0;
            String valueOfA = String.valueOf(A);
            String valueOfB = String.valueOf(B);
            int noDigits = valueOfA.length();
            int[] possible = new int[(B - (A - 1))];
            for(int j = 0; j < (B - (A - 1)); j++) {
                possible[j] = A + j;
            }
            int n = 0;
            int m = 0;
            String valueOfn;
            String valueOfm;
            for(int l = 0; l < possible.length; l++) {
                n = possible[l];
                valueOfn = String.valueOf(n);
                for(int k = 0; k < possible.length; k++) {
                    m = possible[k];
                    valueOfm = String.valueOf(m);
                    if(k != l) {
                        if((A <= n) && (n < m) && (m <= B)) {
                            String s = valueOfn;
                            for(int p = 0; p < noDigits; p++) {
                                
                                s = s.charAt(s.length() - 1) + s.substring(0, (s.length() - 1));
                                if(s.equals(valueOfm)) {
                                    noRecycledPairs++;
                                    p = noDigits;
                                }
                            }
                        }
                    }
                }
            }
            
            System.out.println("Case #" + (i + 1) + ": " + noRecycledPairs);
//            out.close();
        }
    }
}
