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

public class C {

    void solve() throws IOException {
        in("C-large.in"); out("C-large.out");

        long tm = System.currentTimeMillis();
        boolean[] mask = new boolean[2000000];
        int[] r = new int[10];
        int t = readInt();
        for (int cs = 1; cs <= t; ++cs) {
            int a = readInt();
            int b = readInt();
            int ans = 0;
            for (int m = a + 1; m <= b; ++m) {
                char[] d = String.valueOf(m).toCharArray();
                int c = 0;
                for (int i = 1; i < d.length; ++i) {
                    if (d[i] != '0' && d[i] <= d[0]) {
                        int n = 0;
                        for (int j = 0; j < d.length; ++j) {
                            int jj = i + j;
                            if (jj >= d.length) jj -= d.length;
                            n = n * 10 + (d[jj] - '0');
                        }
                        if (n >= a && n < m && !mask[n]) {
                            ++ans;
                            mask[n] = true;
                            r[c++] = n;
                        }
                    }
                }
                for (int i = 0; i < c; ++i) {
                    mask[r[i]] = false;
                }
            }
            println("Case #" + cs + ": " + ans);
            //System.out.println(cs);
        }
        System.out.println("time: " + (System.currentTimeMillis() - tm));
        exit();
    }

    void in(String name) throws IOException {
        if (name.equals("__std")) {
            in = new BufferedReader(new InputStreamReader(System.in));
        } else {
            in = new BufferedReader(new FileReader(name));
        }
    }

    void out(String name) throws IOException {
        if (name.equals("__std")) {
            out = new PrintWriter(System.out);
        } else {
            out = new PrintWriter(name);
        }
    }

    void exit() {
        out.close();
        System.exit(0);
    }

    int readInt() throws IOException {
        return Integer.parseInt(readToken());
    }

    long readLong() throws IOException {
        return Long.parseLong(readToken());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readToken());
    }

    String readLine() throws IOException {
        st = null;
        return in.readLine();
    }

    String readToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    boolean eof() throws IOException {
        return !in.ready();
    }

    void print(String format, Object ... args) {
        out.println(new Formatter(Locale.US).format(format, args));
    }

    void println(String format, Object ... args) {
        out.println(new Formatter(Locale.US).format(format, args));
    }

    void print(Object value) {
        out.print(value);
    }

    void println(Object value) {
        out.println(value);
    }

    void println() {
        out.println();
    }

    StringTokenizer st;

    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        new C().solve();
    }
}

import java.util.ArrayList;
import java.util.LinkedList;

public class RecycledNumbers {
	static String[] zeros = { "0", "00", "000", "0000", "00000", "000000" };

	public static void solve(String fname) {
		Read r = new Read();
		r.Read(fname);
		int numOfTestCases = r.noOfTestCases;
		int[] numbers = r.nums;
		String finalAnser = "";
		for (int i = 0; i < numOfTestCases; i++) {
			String answer = "";
			int firstNum = numbers[2 * i];
			int secondNum = numbers[2 * i + 1];
			
			int lastNumIndex = (int) (secondNum / Math.pow(10, ((secondNum+"").length())-1));
			lastNumIndex++;
			String large="";
			for (int k = 9; k >=lastNumIndex; k--) {
				//check large number
				
					large=large+" "+k;
				
				
			}
			// int mid = ((secondNum-firstNum)/2)+1;
			int noOfans = 0;
			for (int j = firstNum; j < secondNum; j++) {
				String numb = j + "";
				int firstIndex = -1;
				int lastIndex = -1;

				for (int k = zeros.length - 1; k >= 0; k--) {
					// check zeros 
					if (numb.contains(zeros[k])) {
						firstIndex = numb.indexOf(zeros[k]);
						//first index of 0 eg in 201000 it will be 3
						lastIndex = firstIndex + zeros[k].length() - 1;
						//last index = 3+(3-1) = 5 
					}
				}
			
			

				// /LinkedList<Integer> number = new LinkedList<Integer>();
				for (int k = 0; (k < numb.length()) ; k++) {
					if(k>=firstIndex&& (k <= lastIndex)&&(!large.contains(numb.charAt(k)+""))){
					//	System.out.println(k);
					}else{
					String first = numb.substring(0, k);
					String last = numb.substring(k, numb.length());
				//	int la = Integer.parseInt(last);
					String newNumb = last + first;
				//	int biggest = (int) (la * Math.pow(10, numb.length()- last.length()));
		
						int numbC = Integer.parseInt(newNumb);
						if ((numbC <= secondNum) && (numbC > j)) {
							noOfans++;
						}
					
				}
				}
				int x = 0;
				// int k=0;
				// while(!number.isEmpty()){
				// x=(int) (x+number.removeLast()*Math.pow(10, k));
				// k++;
				// }

			}
			
			answer = "Case #" + (i + 1) + ": " + noOfans;
		//	System.out.println(answer);
			finalAnser = finalAnser + answer + "\n";

		}
		r.write("out", finalAnser);
		System.out.println(finalAnser);
	}
	public static void main(String[] args) {

		solve("test");
		// String n = "10002";
		// System.out.println(n.lastIndexOf('0'));
	}
}
