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.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Scanner;

public class recycle {

	public static HashMap<String, String> bigmap = new HashMap<String, String>();

	public static void main(String[] args) throws FileNotFoundException {
		File f = new File("in.in");
		Scanner input = new Scanner(f);
		int k = Integer.parseInt(input.nextLine());
		for (int i = 0; i < k; i++) {
			String[] stuff = input.nextLine().split(" ");
			int a = Integer.parseInt(stuff[0]);
			int b = Integer.parseInt(stuff[1]);
			System.out.println("Case #" + (i + 1) + ": " + doit(a, b));
		}
	}

	public static int doit(int A, int B) {

		HashMap<String, String> m = new HashMap<String, String>();
		int n = 1;
		for (int a = A; a < B; a++) {
			for (int b = a + 1; b <= B; b+=n) {
				n = 1;
				if (bigmap.containsKey(a + "" + b)) {
					m.put(a + "" + b, "");
				} else {
					String s = a + "";
					String q = b + "";
					for (int i = 0; i < s.length(); i++) {
						String old = s;
						char c = s.charAt(s.length() - 1);
						s = c + s.substring(0, s.length() - 1);
						if (s.equals(q)) {
							n = 9;
							m.put(a + "" + b, "");
							bigmap.put(a + "" + b, "");
						}
					}
				}
			}
		}
		return m.size();
	}

}
