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.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class C {

	public static void main(String[] args) throws IOException {
//		Scanner in = new Scanner(new File("in/C/test.in"));
		 Scanner in = new Scanner(new File("in/C/small.in"));
		// Scanner in = new Scanner(new File("in/C/big.in"));
//		BufferedWriter bw = new BufferedWriter(new FileWriter("out/C/test.out"));
		 BufferedWriter bw = new BufferedWriter(new FileWriter(
		 "out/C/small.out"));
		// BufferedWriter bw = new BufferedWriter(new FileWriter(
		// "out/C/big.out"));

		int cases = in.nextInt();
		for (int c = 1; c <= cases; c++) {
			int low = in.nextInt();
			int high = in.nextInt();
			int length = String.valueOf(low).length();
			int count = 0;
			if (length != 1) {
				int maxD = (int) Math.pow(10, length - 1);
				System.err.println("Case " + c + ": Maximum " + maxD);
				for (int k = 1; k < length; k++) {
					int playingWith = (int) Math.pow(10, k);
					int m = (int)Math.pow(10,length-k);
					System.err.println("Playing with " + playingWith);
					for (int j = low; j < high; j++) {
						int first = j / maxD;
						int toMoveFront = j%playingWith;
						int tmpFirst = toMoveFront / (playingWith/10);
						if(tmpFirst < first)
							continue;
						int recycled = toMoveFront * m + j /playingWith;
						if(recycled > high){
							int dif = playingWith-toMoveFront;
							j += dif;
						}else if(recycled > j){
							count++;
						}
					}
				}
			}
			bw.write("Case #" + (c) + ": " + count);
			System.err.println("Case #" + (c) + ": " + count);
			bw.newLine();
		}
		in.close();
		bw.flush();
		bw.close();
	}
}
