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 google.codejam2012.awanish;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;

public class RecycledNumbers {
	static long total = 0;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner inputScan = new Scanner(System.in);
		int noOfCases = Integer.parseInt(inputScan.nextLine());
		long start;
		long end;
		for (int i = 1; i <= noOfCases; i++) {
			total = 0;

			String startend = inputScan.nextLine();
			StringTokenizer st = new StringTokenizer(startend, " ");
			start = Integer.parseInt(st.nextToken());
			end = Integer.parseInt(st.nextToken());
			for (long j = start; j <= end; j++) {
				checkPair(j, start, end);
			}
			System.out.println("Case #" + i + ": " + total/2);

		}

	}

	private static void checkPair(long j, long start, long end) {

		ArrayList a = new ArrayList();
		String tocheck = String.valueOf(j);
		a.add(tocheck);
		for (int c = 0; c < tocheck.length(); c++) {
			tocheck = rotate(tocheck);
			if (!a.contains(tocheck) && !tocheck.substring(0, 1).equals("0")
					&& start <= Integer.parseInt(tocheck)
					&& Integer.parseInt(tocheck) <= end) {
				a.add(tocheck);
				total++;
			}
		}

	}

	private static String rotate(String tocheck) {
		// TODO Auto-generated method stub
		return tocheck.substring(tocheck.length() - 1, tocheck.length())
				+ tocheck.substring(0, tocheck.length() - 1);
	}
}
