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.IOException;
import java.io.InputStreamReader;


public class CodeJam {
static String [][] mapping = new String [6][];
 static String f,s,t,ff,ss,tt;
public static  void map(){
	f = "ejp mysljylc kd kxveddknmc re jsicpdrysi";
	s = "rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd";
	t = "de kr kd eoya kw aej tysr re ujdr lkgc jv";
	ff="our language is impossible to understand";
	ss="there are twenty six factorial possibilities";
	tt="so it is okay if you want to just give up";
	mapping[0] = f.split(" ");
	mapping[1] = ff.split(" ");
	mapping[2] = s.split(" ");
	mapping[3] = ss.split(" ");
	mapping[4] = t.split(" ");
	mapping[5] = tt.split(" ");
}
public static String returnLetter(String l){
	if(l.equals("q")) return "z";
	if(l.equals("z")) return "q";
	for(int i=0;i<6;i+=2){
		for(int j=0;j<mapping[i].length;j++){
			int n;
			if((n=mapping[i][j].indexOf(l))!=-1){
				return mapping [i+1][j].charAt(n)+"";
			}
		}
	}
	return "***";
}
public static boolean isRecycled(String p1, String p2){
	if(p1.length()!=p2.length()) return false;
	for(int i=0;i<p1.length();i++){
		String s = p1.substring((p1.length()-i-1));
		if(p2.indexOf(s)==0 && p2.substring(s.length()).equals(p1.substring(0, (p1.length()-i-1)))) {return true;}
	}
	return false;
}
public static String decode(String sen){
	String res = "";
	for(int i=0;i<sen.length();i++){
		if((sen.charAt(i)+"").equals(" ")) {res+=" ";continue;}
		res = res + returnLetter(sen.charAt(i)+"");
	}return res;
}
public static int enumerate(int low,int high){
	int c=0;
	for(int i=low;i<high;i++){
		for(int j=i+1;j<=high;j++){
		 if(isRecycled(i+"", j+"")) c++;
		}
	}
	return c;
}
public static void main(String [] areg) throws IOException{
	map();
	BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
	int n=Integer.parseInt(bf.readLine());
	for(int i=0;i<n;i++){
		String sen = bf.readLine();
		String [] r = sen.split(" ");
		System.out.println("Case #"+((int)(i+1))+": "+enumerate(Integer.parseInt(r[0]), Integer.parseInt(r[1])));
		
	}
//	String s = bf.readLine();
//	String ss = bf.readLine();
//	System.out.println(enumerate(Integer.parseInt(s), Integer.parseInt(ss)));
	
}



}
