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();
	}
}

import java.awt.Point;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;


public class RecycledNumbers {

	
	public static void main(String[] args) throws FileNotFoundException, IOException {
		int t = 0;
		FileInputStream fstream = new FileInputStream(new File(args[0]));
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		String line = br.readLine();
		t = Integer.parseInt(line);
		System.out.println(t);
		String output;
		FileWriter fw = new FileWriter(new File("C-small-attempt0.out"));
		HashSet<Point> points = new HashSet<Point>();
		
		for(int i = 0; i < t; i++) {
			int counter = 0;
			line = br.readLine();
			
			String[] parameters = line.split(" ");
			int a = Integer.parseInt(parameters[0]);
			System.out.println("a: " + a);
			int number = a;
			int possibleRecycled = 0;
			int b = Integer.parseInt(parameters[1]);
			System.out.println("b: " + b);
			int numberOfDigits = 1;
			while(a/(int)Math.pow(10, numberOfDigits) != 0){
				numberOfDigits++;
			}
		
			while(number <= b){
				int[] digits = new int[numberOfDigits - 1];
				int holder = number;
				int j = 0;
				while (j < numberOfDigits - 1){
					digits[j] = holder % 10;
					holder = holder / 10;
					j++;
				}
				boolean next = true;
				for(int k = 0; k < digits.length && next ; k++){
					if(digits[k] * Math.pow(10, numberOfDigits - 1) < b){
						next = false;
					}
				}
				if(!next){
					int digitStep = 1;
					int lastDigit = 0;
					possibleRecycled = number;
					while(digitStep < numberOfDigits){
						lastDigit = possibleRecycled % 10;
						possibleRecycled = (int) (lastDigit * Math.pow(10, numberOfDigits - 1) + ( possibleRecycled / 10));
						if(possibleRecycled > number && possibleRecycled <= b && !points.contains(new Point(number,possibleRecycled))){
							points.add(new Point(number,possibleRecycled));
							counter++;
//							System.out.println(number + "   " + possibleRecycled );
						}
						digitStep++;
					}
				}
				number++;
			}
			
			output = "Case #" + (i + 1) + ": " + counter + "\n";		
			fw.write(output);
			points.clear();
		}
		fw.flush();
		fw.close();
	}

}
