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.util.*;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] s = new int[3][n];

		for (int i = 0; i < n; i++) {
			s[0][i] = sc.nextInt();
			s[1][i] = sc.nextInt();
			s[2][i] = 0;
		}

		for (int i = 0; i < n; i++) {
			List<Integer> past2 = new ArrayList<Integer>();
			List<Integer> past1 = new ArrayList<Integer>();
			if (s[0][i] < 10 && s[1][i] < 10) {
				s[2][i] = 0;
			} else {
				for (int j = s[0][i]; j < s[1][i]; j++) {
					String t1 = Integer.toString(j); // mÀ» ¹®ÀÚ¿­·Î ÀúÀå
					for (int k = 1; k < t1.length(); k++) {
						String t2 = t1.substring(k) + t1.substring(0, k); // nÀ» ¹®ÀÚ¿­·Î ÀúÀå
						if (t2.charAt(0) != '0') { // Ã¹ÀÚ¸®°¡ 0ÀÌ µÇ¾î ÀÚ¸®¼ö°¡ ³»·Á°¡´Â °æ¿ì ¿¹¿Ü Ã³¸®
							if (Integer.parseInt(t2) <= s[1][i] && Integer.parseInt(t2) >= s[0][i]) { // B ¹üÀ§¸¦ ÃÊ°úÇÏ´Â °æ¿ì ¿¹¿Ü Ã³¸®
								if (!t1.equals(t2)) { // n°ú mÀÌ °°Àº °æ¿ì ¿¹¿Ü Ã³¸®
									int same = 0;
									for(int p = 0; p < past2.size() ; p++) {
										if(past2.get(p) == Integer.parseInt(t1) && past1.get(p) == Integer.parseInt(t2)) {
											same = 1;
										}
									}
									if(same == 0) {
										s[2][i]++;
										past2.add(Integer.parseInt(t2));
										past1.add(Integer.parseInt(t1));
									}
									same = 0;
								}
							}
						}
					}
				}
			}
		}

		for (int i = 0; i < n; i++) {
			System.out.println("Case #" + (i + 1) + ": " + s[2][i]);
		}

	}
}