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.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

public class Runner {

	class ll {
		public lln f;
		public lln l;
	}

	class lln {
		public Object v;
		public lln n;
	}

	private static Scanner sc;

	public static int gi() {
		return Integer.parseInt(sc.next());
	}

	public static String gn() {
		return sc.next();
	}

	public static void main(String[] args) throws IOException {
		System.setIn(new FileInputStream("C-small-attempt2.in"));
		System.setOut(new PrintStream("output.txt"));

		sc = new Scanner(System.in);

		int N = gi();

		for (int z = 0; z < N; z++) {

			int o = gi();
			int t = gi();

			int c = 0;

			for (int m = o + 1; m <= t; m++) {
				for (int n = o; n < m; n++) {
					String ms = new Integer(m).toString();
					String ns = new Integer(n).toString();

					ns = ns.substring(ns.length() - 1) + ns.substring(0, ns.length() - 1);

					for (int i = 0; i < ms.length() - 1; i++) {
						//System.out.println("M: " + ms + " N: " + ns);
						if(ns.equals(ms)) {
							c++;
							break;
						}
						//System.out.println("Pre: " + ns + " ms: " + ms);
						ns = ns.substring(ns.length() - 1) + ns.substring(0, ns.length() - 1);
						//System.out.println("Post: " + ns + " i: " + i);
					}
				}
			}

			System.out.format("Case #%d: %d\r\n", z + 1, c);
		}
	}

}
