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

package algorithm.adhoc;

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

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 4/15/12
 * Time: 1:00 AM
 * To change this template use File | Settings | File Templates.
 */
public class GoogleCodeJam {
    public static void main(String[] arg) throws IOException {
        Scanner scanner = new Scanner(new FileReader("G:\\C-small-attempt1.in"));
        PrintWriter pw = new PrintWriter("output.txt");
        int t, tcase = 1;
        int a, b, start, end, temp;
        int count = 0;
        t = scanner.nextInt();
        String tempStr, tempStr2;
        char[] chars;
        char tmp, temp1;
        while (t > 0) {
            count = 0;
            a = scanner.nextInt();
            b = scanner.nextInt();
            start = a;
            end = b;
            for (int i = start; i <= end; ++i) {
                tempStr = Integer.toString(i);
                if (tempStr.length() != 1) {
                    if (tempStr.length() == 2) {
                        chars = tempStr.toCharArray();
                        tmp = chars[0];
                        chars[0] = chars[1];
                        chars[1] = tmp;
                        tempStr2 = new String(chars);
                        temp = Integer.parseInt(tempStr2);
                        if (temp > i && temp <= b) ++count;
                    } else if (tempStr.length() == 3) {
                        chars = tempStr.toCharArray();
                        tmp = chars[0];
                        chars[0] = chars[2];
                        chars[2] = tmp;
                        tmp = chars[1];
                        chars[1] = chars[2];
                        chars[2] = tmp;
                        tempStr2 = new String(chars);
                        temp = Integer.parseInt(tempStr2);
                        if (temp > i && temp <= b) ++count;
                        chars = tempStr.toCharArray();
                        tmp = chars[0];
                        chars[0] = chars[1];
                        chars[1] = tmp;
                        tmp = chars[1];
                        chars[1] = chars[2];
                        chars[2] = tmp;
                        tempStr2 = new String(chars);
                        temp = Integer.parseInt(tempStr2);
                        if (temp > i && temp <= b) ++count;
                    }
                }
            }

            //System.out.println(count);
            pw.println("Case #" + tcase + ": " + count);
            --t;
            ++tcase;
        }
        pw.close();
        scanner.close();
    }
}
