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.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Scanner;
public class RecycledNumbers {
	
	public static void main(String[] args) throws IOException {
		File file = new File("c:\\java\\results.txt");
		File inFile = new File("c:\\java\\C-large.in");
		file.createNewFile();
		PrintStream out = new PrintStream(file);
		Scanner scanIn = new Scanner(inFile);
		int T = 0;
		int a = 0;
		int b = 0;
		int n = 0;
		int digits = 0;
		HashSet<Pair> set = new HashSet<Pair>();//store results
		T=scanIn.nextInt();
		
		for(int i = 0; i < T; i++){
			a = scanIn.nextInt();
			b = scanIn.nextInt();
			digits = numDigits(a);
			n = a;
			if(a>b){
				//Zero
				out.println("Case #"+(i+1)+": 0");
				continue;
			}
			if(digits == 1){
				//Zero
				out.println("Case #"+(i+1)+": 0");
				continue;
			}
			
			while(n < b){
				int divisor = 10;
				int multiply = (int)Math.pow(10, (digits-1));
				int remain = 0;
				int part = 0;
				int temp = 0;
				for(int j = 0; j < digits-1; j++, divisor*=10, multiply/=10){
					remain = n%divisor;
					part = n/divisor;
					
					temp = (remain*multiply)+part;
					if(temp <= b && temp > n){
						set.add(new Pair(n, temp));
					}
					
					
				}
				
				n++;
			}
			
			out.println("Case #"+(i+1)+": "+set.size());
			
			set.clear();
		}//End of main loop
		
		out.close();
	}
	
	public static int numDigits(int number){
		int divisor = 10;
		int digits = 1;
		while(true){
			if(number%divisor == number){
				return digits;
			}
			else{
				digits++;
				divisor*=10;
			}
		}
	}

}

class Pair{
	int n;
	int m;
	
	public Pair(){
		n = 0;
		m = 0;
	}
	
	public Pair(int n, int m){
		this.n = n;
		this.m = m;
	}
	
	public void printPair(){
		System.out.printf("n: "+n);
		System.out.printf(" m: "+m+"\n");
	}
	
	public boolean equals(Object arg){
		if(this==arg)return true;
        if(arg==null)return false;
        if(arg instanceof Pair){
        	Pair other = (Pair)arg;
            if(this.n == other.n && this.m == other.m){
            	return true;
            }
            else return false;
        }
        return false;
	}
	
	public int hashCode(){
	      int code = 3;
	      code = (code >> 2) + n;
	      code = (code << 2) + m;

	      return code;
	    }
}
