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();
	}
}

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

public class Recycled {
    public static void main(String[] args)throws IOException{
        new SolveRecycled();
    }
}
class SolveRecycled{
    public SolveRecycled()throws IOException
    {
        Scanner sc, oScan,scan;
        System.setOut(new PrintStream(new File("Recycled.out")));
        sc=oScan=scan=new Scanner(new File("Recycled.dat"));

        int runs = Integer.parseInt(sc.nextLine());
        for(int r123=1; r123<=runs; r123++)
        {
            System.out.print("Case #"+r123+": ");
            int A = sc.nextInt();
            int B = sc.nextInt();
            int count=0;
            ArrayList<pair>list = new ArrayList<pair>();
            for(int i=A; i<=B; i++)
            {
                String num=""+i;
                for(int j=0; j<num.length();j++)
                {
                    String t = num.substring(j)+num.substring(0,j);
                    pair p = new pair(i,Integer.parseInt(t));
                    if(!t.equals(num)&&(""+Integer.parseInt(t)).length()==num.length()&&!list.contains(p)&&Integer.parseInt(t)<=B&&i<Integer.parseInt(t))
                    {
                        list.add(p);
//                        System.out.println(p);
                    }
                }
            }
            System.out.println(list.size());

        }
    }


}
class pair{
    int one,two;
    public pair(int o, int t){
        one=o;
        two=t;
    }
    public boolean equals(Object o){
        pair p = (pair)o;
        return p.one==one&&p.two==two||p.one==two&&p.two==one;
    }
    public String toString(){
        return one+" - "+ two;
    }
}