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 jam3;

import java.util.Scanner;

/**
 *
 * @author clary35
 */
public class Jam3 {

    Jam3() {
        System.out.println("Input:");
        Scanner scan = new Scanner(System.in);
        String T = scan.nextLine();
        int cases = Integer.parseInt(T);
        for (int i = 0; i < cases; i++) {
            int A = scan.nextInt();
            int B = scan.nextInt();
            int recycled = 0;
            for (int n = A; n < B; n++) {
                for (int m = n + 1; m <= B; m++) {
                    boolean flag = false;
                    String nstr = Integer.toString(n);
                    String mstr = Integer.toString(m);
 //                   System.out.println("start: "+nstr+" "+mstr);
                    int len = nstr.length();
                    char[] mstrArr = mstr.toCharArray();
                    for (int j = 0; j < (len - 1); j++) {
                        char tmp = mstrArr[len - 1];
                        // one rotation
                        for (int k = (len - 1); k > 0; k--) {
                            mstrArr[k] = mstrArr[k - 1];
                        }
                        mstrArr[0] = tmp;
                        String s = new String(mstrArr);
//                        System.out.print(s + ", ");
                        if (s.equals(nstr)) {
                            flag = true;
//                            System.out.println(recycled+" "+nstr + " " + mstr + " "+s+" "+len);
//                            System.out.println("");
                        }
                    }
//                    System.out.println("");
                    if (flag == true) {
                        recycled++;
                    }
                }
            }

            System.out.println("Case #" + (i + 1) + ": " + recycled);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Jam3 jm = new Jam3();
    }
}
