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

package recycled;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.TreeSet;

/**
 *
 * @author Alfred
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    try {
            FileInputStream fstream = new FileInputStream("C-small-attempt0.in");
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            FileWriter outFile = new FileWriter("out.txt");
            PrintWriter out = new PrintWriter(outFile);
            String line;
            line = br.readLine();
            int cases = Integer.parseInt(line);
            for (int i=1; i<=cases;i++){
                line = br.readLine();
                String[] values = line.split(" ");
                int A = Integer.parseInt(values[0]);
                int B = Integer.parseInt(values[1]);
                int total=0;
                for (int n=A; n<=B;n++){
                    TreeSet<String> solutions = new TreeSet<String>();
                    for (int k=1;k<values[1].length();k++){
                        String m = circshift(n,k);
                        int mVal = Integer.parseInt(m);
                        if(mVal<=B && mVal!=n  && mVal> n && !m.startsWith("0") && m.length()==Integer.toString(n).length() )
                        {
                            solutions.add(m);
                        }                   
                    }
                    total+=solutions.size();
                }
                out.println("Case #"+i+": "+total);
            }
            in.close();
            out.close();
        } catch (Exception e) {//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }

}

    private static String circshift(int n, int k) {
        String nString=Integer.toString(n);
        int len=nString.length();
        String m =  nString.substring(len-k)+nString.subSequence(0, len-k);
        //System.out.println(n+" "+m);
        return m;
    }

}

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

package com.falidae;


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

/**
 *
 * @author LittleRock
 */
public class RecycledNumbers {

    public RecycledNumbers() {
    }

    public void init() {

    }
    
    public long solve(int a, int b) {
        Set<Integer> valid = new HashSet<Integer>();
        long reval = 0l;
        for (int i = a; i <= b; i++) {
            String digits = Integer.toString(i);
            char last = digits.charAt(0);
            boolean allSame = true;
            for (int j = 1; j < digits.length(); j++) {
                if (digits.charAt(j) != last) {
                    allSame = false;
                }
            }
            if (allSame) {
                continue;
            }
            int pow10a = 1;
            int pow10b = (int)Math.pow(10, digits.length());
            valid.clear();
            
            for (int j = 1; j < digits.length(); j++) {
                pow10a *= 10;
                pow10b /= 10;
                int front = i / pow10a;
                int back = i % pow10a;
                int shifted = back * pow10b + front;
//                System.out.println("front " + front + ", back " + back);
//                System.out.println("shifted " + shifted);
                if (Integer.toString(shifted).length() == digits.length() && shifted <= b && shifted > i) {
                    valid.add(shifted);
                }
            }
//            if (valid.size() > 0) {
//                System.out.println(i + " cycle valid " + valid.size());
//            }
            
            reval += valid.size();
        }
        return reval;
    }

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(new FileReader("in.txt"));
        PrintWriter out = new PrintWriter(new FileWriter("out.txt"));
        RecycledNumbers solver = new RecycledNumbers();

        int testCount = in.nextInt();
        for (int i = 0; i < testCount; i++) {
            solver.init();
            printIndex(i, out);
            out.print(solver.solve(in.nextInt(), in.nextInt()));
            out.println();
        }

        in.close();
        out.flush();
        out.close();
    }

    private static void printIndex(int i, PrintWriter out) {
        out.printf("Case #%d: ", i + 1);
    }
}