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.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	private static final int[][] cache;
	private static final int A = 0, B = 2000000;

	static {
		try {
			File f = new File("cache");
			if (f.exists()) {
				cache = (int[][]) new ObjectInputStream(new FileInputStream(f)).readObject();
			} else {
				cache = new int[B+1][];
				for (int j = 12; j < B; j++) {
					int permutation = String.valueOf(j).length();
					HashMap<Integer, Boolean> hit = new HashMap<Integer, Boolean>();
					for (int z = 1; z < permutation; z++) {
						int div = (int) Math.pow(10, z);
						if (j % div >= div / 10) {
							int newnum = j / div + j % div * (int) Math.pow(10, permutation - z);
							if (newnum >= A && newnum <= B && newnum > j) {
								if (hit.get(newnum) == null) {
									hit.put(newnum, true);
								}
							}
						}
					}
					ArrayList<Integer> l = new ArrayList<Integer>(hit.keySet());
					Collections.sort(l);
					int[] vals = new int[l.size()];
					for (int i = 0; i < l.size(); i++) {
						vals[i] = l.get(i);
					}
					cache[j] = vals;
				}

				new ObjectOutputStream(new FileOutputStream(f)).writeObject(cache);
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static void main(String[] args) throws Exception {
		Scanner s = new Scanner(new File("input"));
		BufferedWriter w = new BufferedWriter(new FileWriter(new File("output")));
		int cases = s.nextInt();
		for (int i = 0; i < cases; i++) {
			s.nextLine();
			int a = s.nextInt();
			if (a < 12) {
				a = 12;
			}
			int b = s.nextInt();

			int answer = 0;

			for (int j = a; j < b; j++) {
				int[] vals = cache[j];
				for (int val : vals) {
					if (val < 0) {
						continue;
					}
					if (val > b) {
						break;
					}
					answer++;
				}
			}

			w.write("Case #");
			w.write(String.valueOf(i + 1));
			w.write(": ");

			w.write(String.valueOf(answer));

			w.write("\n");
		}
		w.close();
	}

}
