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.BufferedInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.FileWriter;

class Start{
	BufferedInputStream bis=new BufferedInputStream(System.in);
	PrintWriter out=new PrintWriter(System.out, true);
	int i,j,k,l,m,n,o,p,q,r,s,t,w,x,y,z,ry,rz,rs;
	long a,b,c;
	double d,e,f,g,h;
	char u,v;
	String st;
	int[] in,arr,res;
	final double pi=3.14159265;
	final double l2=0.69314718;

	char chr()throws IOException{
		while((ry=bis.read())==10 || ry==13 || ry==32){}
		return (char)ry;
	}

	int num()throws IOException{
		rz=0;rs=0;
		ry=bis.read(); if(ry=='-') rs=-1; else rz+=(ry-'0');
		while((ry=bis.read())>='0' && ry<='9') rz=rz*10+(ry-'0');
		if(rs==-1) rz=-rz;
		if(ry==13) bis.read();
		return rz;
	}

	String str()throws IOException{
		StringBuilder sb=new StringBuilder();
		while((ry=bis.read())!=10 & ry!=13 && ry!=32) sb.append((char)ry);
		if(ry==13) bis.read();
		return sb.toString();
	}

	String line()throws IOException{
		StringBuilder sb=new StringBuilder();
		while((ry=bis.read())!=10 && ry!=13) sb.append((char)ry);
		if(ry==13)bis.read();
		return sb.toString();
	}

	int log2(double par){return (int)(Math.log(par)/l2);}

	long perm(int p1,int p2){
		long ret=1; int it;
		it=p1; while(it>p2) ret*=it--;
		return ret;
	}

	long comb(int p1,int p2){
		long ret=1; int it;
		if(p2<p1-p2) k=p1-p2;
		it=p1; while(it>p2) ret*=it--;
		it=p1-p2; while(it>1) ret/=it--;
		return ret;
	}

	public void go()throws IOException{
		out =new PrintWriter(new FileWriter("out.txt"),true);
		t=num();
		w=t;
		while(--t>=0){
			a=0;
			y=num();
			z=num();
			if(y<10) y=10;
			p=(int)Math.log10((double)z);
			q=(int)Math.pow(10.0, (double)p);

			for(i=y; i<=z; i++)
			{
				k=i;
				r=p;
				while(r-->0){
					k = (k/10) + ((k%10)*q);
					if(k>i && k<=z) a++;
				}
			}
			out.println("Case #"+(w-t)+": "+a);
		}
		while(bis.available()>0)bis.read();
		out.close();
	}

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