import java.util.*;
import java.io.*;

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
import java.io.*;
import java.util.*;

public class Solution {


	private StringTokenizer st;
	private BufferedReader in;
	private PrintWriter out;
	
	final String file = "C-large";

	public void solve() throws IOException {
		int tests = nextInt();
		int[] pows10 = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};
		for (int test = 0; test < tests; ++test) {
			int a = nextInt();
			int b = nextInt();
			int[] o = new int[6];
			int pow10 = 0;
			int ans = 0;
			for (int i = a; i <= b; ++i) {
				int c = 0;
				while (pows10[pow10] <= i) {
					++pow10;
				}
				for (int sh = 1; sh < pow10; ++sh) {
					int val = i / pows10[sh] + (i % pows10[sh]) * pows10[pow10 - sh];
					if (i < val && val <= b) {
						o[c++] = val;
					}
				}
				Arrays.sort(o, 0, c);
				for (int j = 0; j < c; ++j) {
					if (j == 0 || o[j] != o[j - 1]) {
						ans++;
					}
				}
			}
			out.printf("Case #%d: %d%n", test + 1, ans);
		}
	}

	public void run() throws IOException {
		in = new BufferedReader(new FileReader(file + ".in"));
		out = new PrintWriter(file + ".out");
		eat("");
		
		solve();
		
		out.close();
	}
	
	void eat(String s) {
		st = new StringTokenizer(s);
	}
	
	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			eat(line);
		}
		return st.nextToken();
	}
	
	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	
	long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	
	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	
	public static void main(String[] args) throws IOException {
		Locale.setDefault(Locale.US);
		new Solution().run();
	}
	
}