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.io.*;
import java.util.ArrayList;

public class recycled {
    public static void main(String[] args) {
	String filename = args[0];
	ArrayList<String> input = new ArrayList<String>();
	ArrayList<String> output = new ArrayList<String>();
	try {
	    BufferedReader br = new BufferedReader(new FileReader(filename));
	    while (true) {
		String line = br.readLine();
		if (line == null) break;
		input.add(line);
	    }
	    br.close();
	    input.remove(0);
	} catch (IOException e) {
	    System.out.println("Input error. Try a different filename.");
	}
	for (String line: input) {
	    String out = ""+checkCondition(line);
	    output.add(out);
	}
	try {
	    PrintWriter pr = new PrintWriter(new FileWriter("output.txt"));
	    for (int i = 0;i < output.size();i++) {
		String line = output.get(i);
		pr.println("Case #" + (i+1) + ": " + line);
	    }
	    pr.close();
	} catch (IOException e) {
	    System.out.println("Output error. Hmph.");
	}
	System.out.println("Process complete.");
    }
    private static int checkCondition(String line) {
	String[] numString = line.split(" ");
	int a = Integer.parseInt(numString[0]);
	int b = Integer.parseInt(numString[1]);
	int recycled = 0;
	for (int n = a;n <= b;n++) {
	    String N = ""+n;
	    for (int m = n;m <= b;m++) {
		String M = ""+m;
		if (areRecycled(M,N) && !(M.equals(N))) {
		    recycled++;
		    System.out.println(M + " " + N);
		}
	    }
	}
	return recycled;
    }
    private static boolean areRecycled(String M,String N) {
	String n = N;
	for (int i = 1;i < N.length();i++) {
	    n = permute(n);
	    if (M.equals(n)) {
		return true;
	    }
	}
	return false;
    }
    private static String permute(String n) {
	char q = n.charAt(0);
	return n.substring(1) + q;
    }
}
