import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class C{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int caze, T;
	int A, B;

	void run(){
		T=sc.nextInt();
		for(caze=1; caze<=T; caze++){
			A=sc.nextInt();
			B=sc.nextInt();
			solve();
		}
	}

	void solve(){
		int ans=0;
		for(int n=A; n<=B; n++){
			int digit=(int)(log10(n)+EPS);
			int d=(int)pow(10, digit);
			// debug("n", n);
			for(int m=rot(n, d); m!=n; m=rot(m, d)){
				// debug("m", m);
				if(n<m&&m<=B){
					ans++;
				}
			}
		}
		answer(ans+"");
	}

	int rot(int n, int d){
		return n/10+n%10*d;
	}

	void answer(String s){
		println("Case #"+caze+": "+s);
	}

	void println(String s){
		System.out.println(s);
	}

	void print(String s){
		System.out.print(s);
	}

	void debug(Object... os){
		System.err.println(deepToString(os));
	}

	public static void main(String[] args){
		try{
			System.setIn(new FileInputStream("dat/C-small.in"));
			System.setOut(new PrintStream(new FileOutputStream("dat/C-small.out")));
		}catch(Exception e){}
		new C().run();
		System.out.flush();
		System.out.close();
	}
}

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

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

//<editor-fold defaultstate="collapsed" desc="files">

/**
 *
 * @author toshiba
 */
public class Gjam_3 {

    static String input = "c:\\Gjam\\3\\small.in";
    static String output = "c:\\Gjam\\3\\output.out";

    public static void main(String[] args) throws FileNotFoundException, IOException {
        output o = new output(output);
        ArrayList<String> input_arr = new input().ReadInput(input);
        for (int j = 0; j < input_arr.size(); j++) {
            String[] t = input_arr.get(j).split(" ");
            int a = Integer.parseInt(t[0]);
            int b = Integer.parseInt(t[1]);
            int result = 0;
            for (int n = a; n <= b; n++) {
                String tmp = String.valueOf(n);
                for (int k = tmp.length()-1; k > 0; k--) {
                    tmp = String.valueOf(n).substring(k, String.valueOf(n).length()) +String.valueOf(n).substring(0, k);
                    int m = Integer.parseInt(tmp);
                    if(m==1111)
                        System.out.print(m);
                    if(m>n&&m<=b&&m!=n)
                        result++;
                }
            }
            o.write("Case #" + (j+1) + ": " + result + "\n");
        }
        o.close();
    }
}
class input {

    public ArrayList<String> ReadInput(String input) throws FileNotFoundException, IOException {
        ArrayList a = new ArrayList();
        BufferedReader str = new BufferedReader(new InputStreamReader(new FileInputStream(input)));
        String s = "";
        str.readLine();
        int x = 0;
        while ((s = str.readLine()) != null) {
            x++;
            a.add(s);
        }
        return a;
    }
}
//<editor-fold defaultstate="collapsed" desc="output">
class output {

    FileWriter fstream;
    BufferedWriter bw;

    public output(String output) throws IOException {
        fstream = new FileWriter(output);
        bw = new BufferedWriter(fstream);
    }

    public void write(String result) throws IOException {
        bw.write(result);
    }

    public void close() throws IOException {
        bw.close();
    }
}
//</editor-fold>
//</editor-fold>
