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

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class C {
	
	private Scanner scanner;

	private void solve() throws FileNotFoundException {
		File input = new File("data\\qual\\C-small-attempt0.in");
		scanner = new Scanner(input);

		File test = new File("data\\qual\\C.out");
		PrintStream out = new PrintStream(new FileOutputStream(test));
		System.setOut(out);

		int testCase = scanner.nextInt();
		scanner.nextLine();

		for (int i = 1; i <= testCase; i++) {
			System.out.printf("Case #%d: ", i);
			solveCase();
		}

	}

	private void solveCase() {
		int[] p10 = {
				1,
				10,
				100,
				1000,
				10000,
				100000,
				1000000,
				10000000,
				100000000,
				1000000000
		};
		
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int len = (a + "").length();
		Set ans = new HashSet();
		for (int i = 1; i < len; i++) {
			for (int prefix = p10[i - 1]; prefix < p10[i]; prefix++) {
				for (int suffix = p10[len - i - 1]; suffix < p10[len - i]; suffix++) {
					int n = prefix * p10[len - i] + suffix;
					int m = suffix * p10[i] + prefix;
					if (a <= n && n < m && m <= b) {
//						System.out.println(prefix + "-" + suffix + " " + n + " " + m);
						ans.add(n + "#" + m);
					}
				}
			}
		}
		System.out.println(ans.size());
	}

	public static void main(String[] args) throws FileNotFoundException {
		new C().solve();
	}

}
