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

import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;

public class Recycled_Numbers {

	/**
	 * @param args
	 */
	String rotation(String A, int nRot) {
		String rotA = A.substring(0, nRot);
		A = A.substring(nRot, A.length());
		A = A + rotA;		
		return A;
	}

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		String outputFile = System.getenv("USERPROFILE")+ "\\Documents\\C-small.out";
		String inputFile = System.getenv("USERPROFILE")	+ "\\Documents\\C-small-attempt1.in";

		BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
		DataInputStream reader = new DataInputStream(new FileInputStream(inputFile));
		Recycled_Numbers re = new Recycled_Numbers();

		int T = Integer.valueOf(reader.readLine());
		for (int s = 1; s <= T; s++) {
			String line = reader.readLine();

			long A = Long.valueOf(line.substring(0, line.indexOf(" ")));
			long B = Long.valueOf(line.substring(line.indexOf(" ") + 1,line.length()));
			int n = 0;
			
			for (long i = A; i < B; i++) {
				String rot = Long.toString(i);
				String k = rot;

				for (int j = 1; j < rot.length(); j++) {
					k = re.rotation(rot, j);					
					if (k.equals(rot))
						break;
					if ((Long.valueOf(k) >= i) && (Long.valueOf(k) <= B)) {
						n++;						
					}

				}
			}
			writer.write("Case #" + s + ": " + n);
			writer.newLine();
		}
		writer.close();
		reader.close();
	}
}