import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Q3M {
	public static void main(String[] args) throws Exception {
		compute();
	}

	private static void compute() throws Exception {
		BufferedReader br = new BufferedReader(new FileReader(new File(
				"C:\\work\\Q3\\C-small-attempt0.in")));
		String line = null;
		int i = Integer.parseInt(br.readLine());
		List l = new ArrayList();
		for (int j = 0; j < i; j++) {
			line = br.readLine();
			String[] nums = line.split(" ");
			l.add(calculate(nums));
		}
		writeOutput(l);
	}

	private static int calculate(String[] nums) {
		int min = Integer.parseInt(nums[0]);
		int max = Integer.parseInt(nums[1]);
		int count = 0;
		List l = new ArrayList();
		for (int i = min; i <= max; i++) {
			for (int times = 1; times < countDigits(i); times++) {
				int res = shiftNum(i, times);
				if (res <= max && i < res) {
					if ((!l.contains((i + ":" + res)))) {
						l.add(i + ":" + res);
						l.add(res + ":" + i);
						count++;
					}
				}
			}
		}
		return count;
	}

	private static boolean checkZeros(int temp, int res) {
		if (temp % 10 == 0 || res % 10 == 0)
			return false;
		return true;
	}

	private static int shiftNum(int n, int times) {
		int base = (int) Math.pow(10, times);
		int temp2 = n / base;
		int placeHolder = (int) Math.pow((double) 10,
				(double) countDigits(temp2));
		int res = placeHolder * (n % base) + temp2;
		if (countDigits(res) == countDigits(n)) {
			return res;
		} else {
			return 2000001;
		}
	}

	public static int countDigits(int x) {
		if (x < 10)
			return 1;
		else {
			return 1 + countDigits(x / 10);
		}
	}

	private static void writeOutput(List l) throws Exception {
		StringBuffer b = new StringBuffer();
		int i = 1;
		BufferedWriter br = new BufferedWriter(new FileWriter(new File(
				"C:\\work\\Q3\\ans.txt")));
		for (Iterator iterator = l.iterator(); iterator.hasNext();) {
			br.write("Case #" + i++ + ": " + iterator.next());
			br.newLine();
		}
		br.close();
	}

}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;


public class RecycledNumbers {
	
	
	static int findLessThanHundred(int a, int b){
		if (a==b) return 0;
		if (b < 22) return 0;
		int retour=0;
		if (b < 100) {
			int x=11;
			if (a > 11) x=a; else x = 12;
			while(x < b){
				
		String entier = x+"";
		if (!(entier.charAt(1)+"").equals("0")){
			
		int rec = Integer.parseInt(""+entier.charAt(1)+entier.charAt(0)+"");
				
		if (rec > x && rec < b+1 ) {System.out.println(rec);retour++;}
				
		}
			x++;	
			}
			
			
		return retour;	
			
		}
		
		
		
		
		
		return 0;
	} 
	
	
	static int findLessThanThousand(int a, int b){
		
		int retour = 0;
		ArrayList<String> arr = new ArrayList<String>();
		if (a==b) return 0;
		int x = a;
		while (x < b+1){
		if (!arr.contains(x+"")){
			boolean rec1good = false;
			int rec1=0,rec2=0;
		String entier= x+"";
		if (!(""+entier.charAt(2)+"").equals("0") ){
		rec1 = Integer.parseInt(""+entier.charAt(2)+""+entier.charAt(0)+""+entier.charAt(1)+""); 
		
		if (rec1 > a && rec1 < b+1 && rec1 != x ) {;arr.add(rec1+"");arr.add(x+"");retour++;rec1good=true;}
	
		}
		if (!(""+entier.charAt(1)+"").equals("0") ){
			rec2 = Integer.parseInt(""+entier.charAt(1)+""+entier.charAt(2)+""+entier.charAt(0)+""); 
			
			if (rec2 > a && rec2 < b+1 && rec2 != rec1 && rec2 != x) {arr.add(rec2+"");retour++; if (rec1good) retour++;}
		
			}
		System.out.println("x=="+x+"rec1=="+rec1+"rec2=="+rec2+" retour=="+retour);
		}
		x++;
		}
		
		
		return retour;
	}
	
	
	
	public static void main (String args[]) throws IOException{
	
		BufferedReader in = new BufferedReader(new FileReader(new File("recycled.in")));
		PrintWriter out = new PrintWriter(new FileWriter("recycled.out"));
		
		//System.out.print(RecycledNumbers.findLessThanHundred(10,40));
		
		//System.out.println(RecycledNumbers.findLessThanThousand(100,500));
		
		String ligne="";
		
		int nbr_lignes = Integer.parseInt(in.readLine());
		
		int index = 0;
		
		while(index < nbr_lignes){
		int a,b;
		ligne=in.readLine();
		StringTokenizer tok = new StringTokenizer(ligne);
		
		a = Integer.parseInt(tok.nextToken());
		b = Integer.parseInt(tok.nextToken());	
		
		if (b<100) {
			
			if (index!=nbr_lignes-1){
				out.println("Case #"+(index+1)+": "+RecycledNumbers.findLessThanHundred(a, b));
				}
			else 
				out.print("Case #"+(index+1)+": "+RecycledNumbers.findLessThanHundred(a, b));
			
			
		}
		
		
		else if (a > 99) {
			
			if (index!=nbr_lignes-1){
				out.println("Case #"+(index+1)+": "+(RecycledNumbers.findLessThanThousand(a, b)));
				}
			else 
				out.print("Case #"+(index+1)+": "+(RecycledNumbers.findLessThanThousand(a, b)));
			
							
			}
		
		else {
			
			if (index!=nbr_lignes-1){
				out.println("Case #"+(index+1)+": "+(RecycledNumbers.findLessThanHundred(a, 99)+RecycledNumbers.findLessThanThousand(100, b)));
				}
			else 
				out.print("Case #"+(index+1)+": "+(RecycledNumbers.findLessThanHundred(a, 99)+RecycledNumbers.findLessThanThousand(100, b)));
			
			
			
			
		}
			
			index++;
		}
			
			out.close();
			
			
		}
		
		
	

}
