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

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Scanner;
import java.util.TreeMap;

public class RecycledNumbers {
	private String FILE_NAME = "2012_QC_numbers_C-small-attempt0";
	private TreeMap<Double,Long> numbers;
	private int maxNum = 10000;
	
	private TreeMap<Double,Long> getNumbers() {
		if (numbers == null) {
			String value;
			long newNum;
			
			numbers = new TreeMap<Double,Long>();
			for (int i=10;i<=maxNum;i++) {
				value = String.valueOf(i);
				for (int pos=0;pos<value.length()-1;pos++) {
					long division = Math.round(Math.pow(10,pos+1)); 
					int power = value.length()-pos-1; 
					newNum = Math.round(i/division + (i%division)*Math.pow(10,power));
					
					if (i<newNum && newNum<=maxNum && value.length()==String.valueOf(newNum).length()) {
						numbers.put(Double.valueOf(i+"."+newNum),newNum);
					}
				}
			}
		}
		return numbers;
	}

	private int solve(String input) {
		Scanner sc = new Scanner(input);
		
		double lowest = sc.nextInt();
		double highest = sc.nextInt();
		int count = 0;
		
		NavigableMap<Double,Long> recycles = getNumbers().subMap(lowest, true, highest, true);
		for (Map.Entry<Double, Long> recycle : recycles.entrySet()) {
			if (recycle.getValue()<highest+1) {
				count++;
			}
		}
		
		return count;
	}
	
	public void run() throws IOException {
		Scanner sc = new Scanner(new FileReader(FILE_NAME+".in"));
		PrintWriter pw = new PrintWriter(new FileWriter(FILE_NAME+".out"));
		
		int cases = Integer.valueOf(sc.nextLine());
		for (int i=1;i<=cases;i++) {
			String input = sc.nextLine();
			System.out.println("Input #"+i+": "+input);

			String output = "Case #"+i+": "+solve(input);
			pw.println(output);
			System.out.println(output);
		}
		
		pw.flush();
		pw.close();
		sc.close();
	}
	public static void main(String[] args) throws IOException {
		new RecycledNumbers().run();
	}
}
