import java.io.*;
import java.math.BigInteger;
import java.util.*;

import org.jfree.data.function.PowerFunction2D;

public class r2a
{

	Map numMap = new HashMap();
    int output = 0;

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        r2a mk = new r2a();
        try {
            FileInputStream fstream = new FileInputStream("d:/cjinput.txt");
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String str;
            int i = 0;
            while ((str = br.readLine()) != null) {
            	int begin=0,end = 0;
                i++;
                if (i == 1)
                    continue;
                mk.numMap = new HashMap();
                StringTokenizer strTok = new StringTokenizer(str, " ");
                while (strTok.hasMoreTokens()) {
                	begin =  Integer.parseInt(((String) strTok.nextToken()));
                    end = Integer.parseInt(((String) strTok.nextToken()));
                }

                mk.evaluate(i, begin, end);

            }
            in.close();
        }
        catch (Exception e) {
            System.err.println(e);
        }

    }

    private void evaluate(int rowNum, int begin, int end)
    {
    	output=0;
    	for (int i = begin; i<= end; i++) {
    		if(numMap.containsKey(Integer.valueOf(i)))
    			continue;
    		List l = getPairElems(i);
    		if (l.size() > 0) {
    			Iterator itr = l.iterator();
    			int ctr = 0;
    			ArrayList tempList = new ArrayList();
    			while (itr.hasNext()) {
    				int next = ((Integer)itr.next()).intValue();
    				if (next <= end && next > i) {
    					numMap.put(Integer.valueOf(next), i);
    					tempList.add(next);
    					ctr++;
    				}
    			}
    			ctr = getCounter(ctr+1,2);
/*    			if (tempList.size() > 0 || ctr > 0)
    				System.out.println("DD: " + i + ": " + tempList +" ; ctr = " + ctr);*/
    			output = output + ctr;
    		}
    		
    	}

        String outputStr = "Case #" + (rowNum -1) + ": " + output;
        
        System.out.println(outputStr);
    }

	private int getCounter(int n, int r) {
		int ret = 1;
		int nfactorial =1;
		for (int i = 2; i<=n; i++) {
			nfactorial = i*nfactorial;
		}
		int nrfact =1;
		for (int i = 2; i<=n-r; i++) {
			nrfact = i*nrfact;
		}
		
		return nfactorial/(2*nrfact);
	}

	private ArrayList getPairElems(int num) {
		ArrayList retList = new ArrayList();
		int temp = num;
		if (num/10 == 0)
			return retList;
		
		String str = String.valueOf(num);
		
		int arr[] = new int[str.length()];
		int x = str.length();
		while (temp/10 > 0) {
			arr[x-1] = temp%10;
			temp=temp/10;
			x--;
		}
		arr[0]=temp;
		
		int size = arr.length;
		for (int pos = size -1; pos >0; pos--) {
			if(arr[pos] == 0)
				continue;
			int pairNum = 0;
			int multiplier =1;
			for (int c=0; c < size-1; c++) {
				multiplier = multiplier*10;
			}
			pairNum = pairNum + (arr[pos]*multiplier);
			for(int ctr = pos+1, i=1; i < size; i++,ctr++) {
				if (ctr == size)
					ctr=0;
				if (multiplier!=1)
					multiplier=multiplier/10;
				pairNum = pairNum + (arr[ctr]*multiplier);
			}
			if (pairNum != num)
				retList.add(Integer.valueOf(pairNum));			
		}
		
		return retList;
	}
}

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();}
}
